Quick question about a loop

Hi --

I'm writing a little recipe application, and I want my user profile pages to list that particular user's recipes.

I can't figure out how to have the code say "Display all of the recipes where the user_id column equals the id of this particular user profile".

If you've done the "wiring" correctly (table and column names, model names and associations), you should be able to do something like:

   <% @user.recipes.each do |recipe| %>     .... do stuff with recipe here ....    <% end %>

This is predicated on:

   * a user_id column in the recipes table    * this line in the user.rb model class:

       has_many :recipes

   * this line in the recipe.rb model class:

       belongs_to :user

And the assumption is that whenever you create a recipe, you assign a user to it -- like this:

   recipe.user = user

or

   user.recipes << recipe

All of this is just the basic (but very powerful) mechanism by which ActiveRecord lets you use nice high-level Ruby commands, like @user.recipes, to manipulate database-level relationships.

David