Rails:在多选表单字段中显示选定的值

问题描述:

我创建了一个多选字段,我可以看到我将值数组保存到数据库,但是当我返回到表单时,值在实际表单域中显示为选中状态。Rails:在多选表单字段中显示选定的值

在此示例中,“ringmetaltype”是我在“项目”表中的字段。对于它的价值,我也是在项目控制器的最新item_params包括“:ringmetaltype => []”

<%= form.select :ringmetaltype, options_for_select(["10K White Gold", "14K White Gold", "18K White Gold"],:selected => @item.ringmetaltype),{},{:multiple => true, :class => "form-control"} %> 
+0

更改':ringmetaltype'到':ringmetaltypes' –

+0

谢谢,但它没有奏效。一个迁移,改变列的名称,以包括“s”,仍然没有运气。 – Mark

我搜索了几个小时之后想通了这一点。我需要添加

serialize :ringmetaltype 

我的模型。发现我的答案在这里:https://*.com/a/11934886/5101088