Home > Blockchain >  Rails collection check boxes set checkboxes as default checked
Rails collection check boxes set checkboxes as default checked

Time:06-02

I have like to set all the check boxes here to be checked by default. I tried a few methods from so but somehow could not get it to work.

  <div >
        <%= f.collection_check_boxes(:clazz, @staff.clazzes.map { |c| 
              [ ' '   c.name   ' ', c.id]
        }, :last, :first) %>
  </div>

Any help or suggestion would be greatly appreciated.

The whole form looks like this: https://gist.github.com/somaria/7d2bd484b8a45fa0623337ec397dfd3e

CodePudding user response:

Something like this

<div >
  <%= f.collection_check_boxes(:clazz, @staff.clazzes.map { |c| [ " #{c.name} ", c.id] }, :last, :first) do |b| %>
    <%= b.label { b.check_box(checked: true)   b.text } %>
  <% end %>
</div>
  • Related