Search code examples
htmlcssruby-on-railscheckboxform-helpers

Customising collection_check_boxes


<%= f.collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b| %>
   <% b.label { b.check_box + b.text } %>
<% end %>

The above code outputs the html as

<label tag>
    <input checkbox tag></checkbox>
    value of b.text
</label>

Can it be modified to output the html(i.e label tag after input tag) as

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

Tried various combinations with collection_check_boxes but couldn't succeed.


Solution

  • <%= f.collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b| %>
       <%= b.check_box %>
       <%= b.label %>
    <% end %>