ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Rolling with Ruby on Rails, Part 2
Subject:   How to?? : Showing related Recipes from the Category list
Date:   2005-12-05 14:37:36
From:   Marco13
Response to: How to?? : Showing related Recipes from the Category list

Step 1:

Create a list method for Category controller:

def list
@categories = Category.find_all
end



Step 2:

Since we changed the controller, we now have to create a custom view for the list method as app\controller\list.rhtml. You do the same as you did for recipe, but where you have the category name column, you'll use the code:

<td><%= link_to category.name, :controller=>"recipe", :action=>"list", :category=>category.name %></td>

This way, you're turning the category name into a link that will invoke the /recipe/list link while setting the @category to the selected category name.


I just did that, and it worked for me...
--marco