【发布时间】:2016-09-07 01:08:52
【问题描述】:
Rails 视图有两个参数
list_of_attributes = ["a1", "a2", "a3", "a4"]
user_selections = ["a2", "a4"]
我能够使用以下 simple_form 定义显示适当的复选框和任何相关的用户选择
<% list_of_attributes.each do |item| %>
<label>
<%= check_box_tag "user_selections[]", item, user_selections.include?(item) %>
<%= item %>
</label>
<% end %>
如何使用 simple_form f.input 语法定义上述行为?通过以下定义,我可以显示适当的复选框,但任何用户选择都不会被“选中”。
<%= f.input key, as: :check_boxes, collection: list_of_attributes,
:label => key, class: "form-control" %>
感谢您的帮助。
【问题讨论】:
标签: checkbox simple-form ruby-on-rails-5