如何在simple_fields_for中进行多选

时间:2014-10-08 12:57:18

标签: ruby-on-rails nested-forms polymorphic-associations

我已经写了以下内容来接受角色,如何让它接受多个值

= f.simple_fields_for :content_roles do |role|
  = role.input :role_id, label: "visible to", as: :select, label: "Role", collection: Role.all, required: true

2 个答案:

答案 0 :(得分:2)

只需将multiple: true添加到您的角色字段。

像这样:

= role.input :role_id, label: "visible to", as: :select, label: "Role", collection: Role.all, required: true, multiple: true

答案 1 :(得分:2)

这是我当前在线项目中的代码。更新缺少的红宝石标签....