<%= f.collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b| %>
<% b.label { b.check_box + b.text } %>
<% end %>
上面的代码将html输出为
<label tag>
<input checkbox tag></checkbox>
value of b.text
</label>
是否可以修改为输出 html(即 输入标签后的标签标签
)作为
<input checkboxtag></checkbox>
<labeltag>
value of b.text
</labeltag>
尝试了与 collection_check_boxes
的各种组合,但未能成功。
最佳答案
<%= f.collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b| %>
<%= b.check_box %>
<%= b.label %>
<% end %>
关于html - 自定义 collection_check_boxes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35383759/