how to save array to database in rails

前端 未结 4 853
我在风中等你
我在风中等你 2020-12-10 01:07

if i have params like this :

params[\"scholarship\"] = {\"name\"=>\"test\", \"state_ids\"=>[\"1\", \"2\", \"3\", \"4\"]}

and when i c

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-10 01:26

    state_ids != state_id
    

    you've got 2 different names for your attribute, so they don't line up. then use serialize :state_ids once you've renamed the column.

    However if you're storing a list of state_ids, i'm going to guess you also have a states table, and so should look into using has_and_belongs_to_many association.

提交回复
热议问题