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 categor开发者_StackOverflow社区y. And ideas on that?
In your controller:
@category = Category.find(params[:id])
@products = @category.products
and then in view:
<% @products.each do |p| %>
<p><%= p.name %></p>
<% end %>
精彩评论