Rails 4.0 image_tag size选项不起作用

时间:2013-12-09 16:24:46

标签: ruby-on-rails

我想使用image_tag尺寸

应用程序/助手/ application_helper.rb

def fooimage(size)
  image_tag size: "#{size}"
end

应用程序/视图/家/ index.html.haml

=fooimage("large")

但是,不工作。为什么呢?

2 个答案:

答案 0 :(得分:5)

我不相信大小会用文字(即大,中等)来论证。

您可以稍微修改您的fooimage方法:

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

并称之为......

<%= fooimage "logo.png", "large" %>

答案 1 :(得分:0)

您需要提供图像文件名作为image_tag的第一个参数。

image_tag <filename>, size: <size>

欲了解更多信息,请参阅:

http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-image_tag