Rails 集合复选框将复选框设置为默认选中
Rails collection check boxes set checkboxes as default checked
我想把这里所有的复选框设置为默认选中。我尝试了一些方法,但不知何故无法正常工作。
<div class="mr-6 text-xs">
<%= f.collection_check_boxes(:clazz, @staff.clazzes.map { |c|
[ ' ' + c.name + ' ', c.id]
}, :last, :first) %>
</div>
如有任何帮助或建议,我们将不胜感激。
整个表格如下所示:
https://gist.github.com/somaria/7d2bd484b8a45fa0623337ec397dfd3e
像这样
<div class="mr-6 text-xs">
<%= f.collection_check_boxes(:clazz, @staff.clazzes.map { |c| [ " #{c.name} ", c.id] }, :last, :first) do |b| %>
<%= b.label { b.check_box(checked: true) + b.text } %>
<% end %>
</div>
我想把这里所有的复选框设置为默认选中。我尝试了一些方法,但不知何故无法正常工作。
<div class="mr-6 text-xs">
<%= f.collection_check_boxes(:clazz, @staff.clazzes.map { |c|
[ ' ' + c.name + ' ', c.id]
}, :last, :first) %>
</div>
如有任何帮助或建议,我们将不胜感激。
整个表格如下所示: https://gist.github.com/somaria/7d2bd484b8a45fa0623337ec397dfd3e
像这样
<div class="mr-6 text-xs">
<%= f.collection_check_boxes(:clazz, @staff.clazzes.map { |c| [ " #{c.name} ", c.id] }, :last, :first) do |b| %>
<%= b.label { b.check_box(checked: true) + b.text } %>
<% end %>
</div>