views:

25

answers:

1

I have many products, each product belong to one category. How can I generate each category in hyper text, and when I click on the category hyper text, I can get all the products which is belongs to this category. And ideas on that?

A: 

In your controller:

@category = Category.find(params[:id]) 
@products = @category.products

and then in view:

<% @products.each do |p| %>
  <p><%= p.name %></p>
<% end %>
klew