Women in Technology

Hear us Roar



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!!!


Now I want to show my Recipes from my Category list page. Can somebody tell me how to do that?
I've been struggling for quite a while now..

Main Topics Oldest First

Showing messages 1 through 1 of 1.

  • How to?? : Showing related Recipes from the Category list
    2005-12-05 14:37:36  Marco13 [View]

    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