Reputation: 7
I want to use image_tag size
app/helpers/application_helper.rb
def fooimage(size)
image_tag size: "#{size}"
end
app/views/home/index.html.haml
=fooimage("large")
but,not working. why?
Upvotes: 0
Views: 5925
Reputation: 15917
You need to supply the image filename as the first parameter to image_tag.
image_tag <filename>, size: <size>
For more info, please see:
http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-image_tag
Upvotes: 0
Reputation: 2951
I do not believe that size takes in arguments in words (i.e. large, medium, etc).
You can modify your fooimage method a bit:
def fooimage(image_path, size)
if size == "large"
actual_size = "200x200"
elsif size == "medium"
acutual_size = "100x100"
else
actual_size = "50x50"
end
image_tag image_path, size: "#{actual_size}"
end
And, call it like...
<%= fooimage "logo.png", "large" %>
Upvotes: 5