Skip to content

Instantly share code, notes, and snippets.

@kattak
Last active January 9, 2017 15:43
Show Gist options
  • Save kattak/443cc3bea263dd04ff9225e54ceca659 to your computer and use it in GitHub Desktop.
Save kattak/443cc3bea263dd04ff9225e54ceca659 to your computer and use it in GitHub Desktop.

#Checkbox Field

<div class="field">
<%= f.label "Mechanics in Game:" %><br />
<%= f.collection_check_boxes :mechanic_ids, @mechanics.all, :id, :name do |m| %>
  <div class="collection-check-box">
    <%= m.check_box %>
    <%= m.label %>
  </div>
<% end %>
</div 

#What the whole form looks like:

<%= form_for(game) do |f| %>
  <% if game.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(game.errors.count, "error") %> prohibited this game from being saved:</h2>

      <ul>
      <% game.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.text_field :name, placeholder: 'Name' %>
  </div>

  <div class="field">
    <%= f.text_field :description, placeholder: 'description' %>
  </div>

  <div class="field">
    <%= f.text_field :picture, placeholder: 'link to picture' %>
  </div>

  <div class="field">
  <%= f.label "Mechanics in Game:" %><br />
  <%= f.collection_check_boxes :mechanic_ids, @mechanics.all, :id, :name do |m| %>
    <div class="collection-check-box">
      <%= m.check_box %>
      <%= m.label %>
    </div>
  <% end %>
  </div

  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>
</center>```

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