【问题标题】:Rails: Display Selected Value in Multi Select Form FieldRails:在多选表单字段中显示所选值
【发布时间】:2017-10-14 04:42:40
【问题描述】:

我创建了一个多选字段,我可以看到我正在将值数组保存到数据库中,但是当我返回表单时,这些值不会显示为实际表单字段中的选定值.

在本例中,“ringmetaltype”是我在“items”表中的字段。值得一提的是,我还更新了 items 控制器中的 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"} %>

【问题讨论】:

  • :ringmetaltype更改为:ringmetaltypes
  • 谢谢,但没用。进行了迁移,将列名更改为包含“s”,但仍然没有运气。

标签: ruby-on-rails ruby twitter-bootstrap


【解决方案1】:

经过数小时的搜索,我发现了这一点。我需要添加

serialize :ringmetaltype

到我的模型。在这里找到我的答案:https://stackoverflow.com/a/11934886/5101088

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-31
    相关资源
    最近更新 更多