Reputation: 1287
I have an Image model that is linked by a many-to-one relationship with the Post model.
On the index action I would like to display only the first image. @post.images.each
works well but @post.image.first
does not. So what I am wondering is: while in the view how does one display only the first record from the images array?
Upvotes: 0
Views: 1398
Reputation: 13181
As you have a many-to-one relationship:
@post.images
(with a 's') is a collection of images@post.image
(without 's') does not exist So to get the first image you must use: @post.images.first
(with a 's')
Upvotes: 2