Reputation: 897
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
Reputation: 3826
You can use gallery's user
attribute :
<%= image_tag @gallery.user.image %>
Upvotes: 2