how to save array to database in rails

前端 未结 4 845
我在风中等你
我在风中等你 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:38

    Also you can use PostrgreSQL support for array storing. (If you're using PG of course). Your migration will look like that:

    add_column :table_name, :column_name, :string, array: true, default: []
    

    But don't forget about validations.

提交回复
热议问题