ruby on rails - "Category(#2203433720) expected, got String(#2155957040)" Collection_select returning string instead of integer -


My two models are "Events" and "Categories" in the event model there is an integer type "category" which is "range" which is belong_to The category is the key to the model: Price which stores these categories 1: Medical 2: Health 3: food, etc.

  class event & lt; ActiveRecord :: Base is_to: category end class category & lt; ActiveRecord :: Base has_many: events, foreign_key: "category" end  

My schema is:

  create_table "categories", force: true do | T | T.string "name" t.datetime "created_at" t.datetime "updated_at" end create_table "events", force: true do | T | T.string "name" t.integer "category" t.datetime "created_at" t.datetime "updated_at" end  

I am using simple forms and probably this is the place Where I am going wrong but I am returning the right value, but in the form of a string. For example, if I select medical from the drop down then it will return the correct "1", but not just the required integer as a string.

/ view / event

  & lt;% = f.input: Category, as :: Select, Archive: category. All, include_blank: "Any category Select ... "%>  

My drop down is displaying properly and returning the correct value but in the form of a string and not an integer is it the best way to decide?

In the form of you f.input: category_id , as you submit Being done, the ID of the category you selected is not that category.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -