| Article: |
Rolling with Ruby on Rails, Part 2 | |
| Subject: | How to?? : Showing related Recipes from the Category list | |
| Date: | 2005-11-12 10:38:34 | |
| From: | micheldogger | |
|
In the tutorial was explaned how you can show the recipes related to a specific category. This was done from the recipes list page. This works fine!!!
|
||
Showing messages 1 through 1 of 1.
-
How to?? : Showing related Recipes from the Category list
2005-12-05 14:37:36 Marco13 [View]



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