Hey,

I followed Ryan Bates tutorials here about implemting checkboxes with
has and belongs to many relationships.

http://railscasts.com/episodes/17-habtm-checkboxes

In case you dont have time to watch it, heres a quick summary--

----------------------------------------------------------------------------

Products and categories have the has and belongs to many relationship
between them.

Then, in the products form, you can put this for creating check boxes,
the ultimate goal of assigning this product with many categories--

<% for category in Category.find(:all) %>
<div>
  <%= check_box_tag "product[category_ids][]", category.id,
@product.categories.include?(category) %>
  <%= category.name %>
</div>
<% end %>

---------------------------------------------------------------

Ok great, that works.

the checkboxes all submit. It works great.


But my question is--

How can I display what categories a certain product belongs to? Most
likely using a FOR loop, but I'm not too sure how to make one that
displays the categories of a product.

Thanks, and feel free to ask more questions if u dont understand :)
thanks

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to