Remco
Remco

Reputation: 683

Show first record

I have this code:

@country.assets.each do |asset|                           
  image_tag(asset.image.url(:original), :height=>"300px", :width=>"630px")
end

I shows 10 images of the country. I want also show only the first image in my text. How can i do this?

Upvotes: 0

Views: 97

Answers (2)

topek
topek

Reputation: 18979

image_tag(@country.assets.first.image.url(:original), :height=>"300px", :width=>"630px")

But note that this is not a great idea to do in the view. It would be better to create an instance variable in the controller:

@first_country_asset = @country.first.asset

And than create the image tag. Otherwise you start cluttering your views.

Upvotes: 2

fl00r
fl00r

Reputation: 83680

image_tag(@country.assets.first.image.url(:original), :height=>"300px", :width=>"630px")

Upvotes: 0

Related Questions