Danny Connolly
Danny Connolly

Reputation: 897

Joining models in rails

I have a gallery model with image and user id. On the gallery index i would like to show the image with the user name. How do I retrieve username with the user id in the gallery model?

my relationships are

user has_many galleries

gallery belongs_to user

I am getting the user id through a hidden field which captures current user.

Upvotes: 0

Views: 40

Answers (1)

Cydonia7
Cydonia7

Reputation: 3826

You can use gallery's user attribute :

<%= image_tag @gallery.user.image %>

Upvotes: 2

Related Questions