# Quick question about a loop

**URL:** <https://discuss.rubyonrails.org/t/quick-question-about-a-loop/4341>\
**Category:** rubyonrails-talk\
**Created:** [November 10, 2006, 2:49am UTC](https://discuss.rubyonrails.org/t/quick-question-about-a-loop/4341 "2006-11-10T02:49:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_A\_Black1](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@David\_A\_Black1](https://discuss.rubyonrails.org/u/David_A_Black1)\
**Post date:** [November 10, 2006, 2:49am UTC](https://discuss.rubyonrails.org/t/quick-question-about-a-loop/4341/1 "2006-11-10T02:49:59Z")

</div>

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:

&nbsp;&nbsp;&nbsp;\<% @user.recipes.each do |recipe| %\> &nbsp;&nbsp;&nbsp;&nbsp;.... do stuff with recipe here .... &nbsp;&nbsp;&nbsp;\<% end %\>

This is predicated on:

&nbsp;&nbsp;&nbsp;\* a user\_id column in the recipes table &nbsp;&nbsp;&nbsp;\* this line in the user.rb model class:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;has\_many :recipes

&nbsp;&nbsp;&nbsp;\* this line in the recipe.rb model class:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;belongs\_to :user

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

&nbsp;&nbsp;&nbsp;recipe.user = user

or

&nbsp;&nbsp;&nbsp;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
