Skip to content

Instantly share code, notes, and snippets.

@JoshReedSchramm
Created October 27, 2013 00:05
Show Gist options
  • Save JoshReedSchramm/7176154 to your computer and use it in GitHub Desktop.
Save JoshReedSchramm/7176154 to your computer and use it in GitHub Desktop.
An example of customizing collection_check_boxes in Rails 4. -- I'm working on converting a rails 3.2 app to Rails 4 and noticed that a couple of helpers from simple_form are now in the Rails core. I wanted to move away from dependencies as much as possible including getting rid of simple_form if possible so I went about converting the old view …
<%= f.collection_check_boxes :venue_ids, Venue.all, :id, :name, checked: Venue.all.map(&:id) do |b| %>
<span>
<%= b.check_box %>
<%= b.label %>
</span>
<% end %>
@moyuanhuang
Copy link

@vishal5963

a little hacky way of achieving this:

    <% primary_options = my_options.collect do |option| %>
      <% [option,option] %>
    <% end %>

    <%= p.collection_check_boxes :my_options, primary_options, :first, :last do |option| %>
      <%= option.check_box + option.text %>
      <% if option.text == 'Other' %>
          <input type='text' id='other-input' class='other-textbox' value="option_group_other">
      <% end %>
    <% end %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment