Rails: Pass association object to the View

Posted by Fedyashev Nikita on Stack Overflow See other posts from Stack Overflow or by Fedyashev Nikita
Published on 2010-05-19T06:21:59Z Indexed on 2010/05/19 6:30 UTC
Read the original article Hit count: 173

Model Item belongs_to User.

In my controller I have code like this:

@items = Item.find(:all)

I need to have a corresponding User models for each item in my View templates.

it works in controller(but not in View template):

@items.each { |item| item.user }

But manual looping just to build associations for View template kinda smells. How can I do this not in a creepy way?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about best-practices