Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails collection_check_boxes - wrap each checkbox with <li>

Brand new to Rails. How do I add a <li> wrapper to each checkbox / label element generated by the following code?

<%= f.collection_check_boxes :publish_to, [['YouTube'], ['Hulu'], ['Roku'], ['Owned Website'], ['Other']], :first, :first %>

The final outputted HTML would look like:

<li class="checkbox-wrap">
  <label></label>
  <input type="checkbox"/>
</li>

Thanks in advance!

like image 919
Aaron C. Avatar asked Mar 16 '23 02:03

Aaron C.


1 Answers

It's possible. collection_check_boxes allows you to do it like this:

<ul>
<%= f.collection_check_boxes :publish_to, [['YouTube'], ['Hulu'], ['Roku'], ['Owned Website'], ['Other']], :first, :first do |b| %>
  <li>
    <%= b.label %>
    <%= b.check_box %>
  </li>
<% end %>
</ul>

Works on Rails 5 as well.

Reference: https://apidock.com/rails/v4.2.1/ActionView/Helpers/FormOptionsHelper/collection_check_boxes

like image 88
haris Avatar answered Mar 23 '23 14:03

haris