user3061082
user3061082

Reputation: 7

Rails 4.0 image_tag size option not working

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

Answers (2)

Donovan
Donovan

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

Yosep Kim
Yosep Kim

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

Related Questions