Skip to content

Instantly share code, notes, and snippets.

@itsNikolay
Created March 2, 2012 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsNikolay/1960802 to your computer and use it in GitHub Desktop.
Save itsNikolay/1960802 to your computer and use it in GitHub Desktop.
<%= form_for (@products) do |f| %>
<%= f.label "Colors" %>
<% for color in Color.all %>
<%= check_box_tag 'product[color_ids][]', color.id,
@product.color_ids.include?(color.id), :id => dom_id(color) %>
<%= label_tag dom_id(colore), color.name, :class => "check_box_label" %>
<br />
<% end %>
class Place < ActiveRecord::Base
has_and_belongs_to_many :products
end
class Contract < ActiveRecord::Base
has_and_belongs_to_many :colors
end
create_table "products", :force => true do |t|
t.string "color"
end
create_table "products_colors", :id => false, :force => true do |t|
t.integer "product_id"
t.integer "color_id"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment