开发者

Generate information based on content in RoR, any ideas on that?

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 %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜