【问题标题】:Customising collection_check_boxes自定义 collection_check_boxes
【发布时间】:2016-02-13 18:34:07
【问题描述】:
<%= 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(即label tag after input tag)为

<input checkboxtag></checkbox>
<labeltag>
    value of b.text
</labeltag>

尝试了与collection_check_boxes 的各种组合,但均未成功。

【问题讨论】:

    标签: html css ruby-on-rails checkbox form-helpers


    【解决方案1】:
    <%= f.collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b| %>
       <%= b.check_box %>
       <%= b.label %>
    <% end %>
    

    【讨论】:

    • 谢谢。应该是&lt;%= b.check_box %&gt;&lt;%= b.label %&gt;
    • 是的,不知道那条流浪评论是从哪里偷来的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-05
    • 2014-09-22
    • 1970-01-01
    相关资源
    最近更新 更多