Skip to content

Instantly share code, notes, and snippets.

@HungYuHei
Created September 15, 2011 06:53
Show Gist options
  • Select an option

  • Save HungYuHei/1218687 to your computer and use it in GitHub Desktop.

Select an option

Save HungYuHei/1218687 to your computer and use it in GitHub Desktop.
has_and_belongs_to checkbox
// VIEW:
<% for category in Category.find(:all) %>
<div>
<%= check_box_tag "product[category_ids][]", category.id, @product.categories.include?(category) %>
<%= category.name %>
</div>
<% end %>
// CONTROLLER:
params[:product][:category_ids] ||= []
// MODEL
attr_accessible :category_ids
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment