Reputation: 683
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
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
Reputation: 83680
image_tag(@country.assets.first.image.url(:original), :height=>"300px", :width=>"630px")
Upvotes: 0