我试图默认选中这一行<%= f.collection_check_boxes :committed, checked, Date::ABBR_DAYNAMES, :downcase, :to_s, %>
In db t.text "committed"
.
我尝试过的变体checked
& true
,但也许我忽略了一些事情。
这是Gist http://gist.github.com/RallyWithGalli/c66dee6dfb9ab5d338c2 of it.
这是关于如何将选中添加为默认值到 collection_check_boxes 表单助手的快速答案,因为我花了一些时间才弄清楚。将其分成一个块,您可以设置检查并添加类。更多信息请访问http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_check_boxes http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_check_boxes.
<%= f.collection_check_boxes(:author_ids, Author.all, :id, :name) do |b| %>
<%= b.label(class: "check_box") { b.check_box(checked: true, class: "add_margin") + b.text } %>
<% end %>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)