Liz
Liz

Reputation: 1437

Printing First Photo in Array with Ruby/ERB

I'm trying to show just the first photo in an array, but for some reason it's not behaving as I expect it to. I consulted this SO post, but something isn't working. When I put:

<% listing.listing_property_details.images.each do |image_url| %>
     <%= image_tag image_url, class: "fancy-border" %>
<% end %>

It displays five images (the entire array). However, when I change each to first (as was recommended in the consulted SO posts) all the images disappear. What am I missing?

Upvotes: 0

Views: 59

Answers (1)

Brennan
Brennan

Reputation: 5722

<%= image_tag listing.listing_property_details.images.first, class: "fancy-border" %>

Upvotes: 1

Related Questions