如何将类添加到image_tag rails helper

con*_*t01 44 ruby-on-rails image helper lccs

我有以下代码:

<%= image_tag iterator.image.url(:small), :class => "img_preview" %>
Run Code Online (Sandbox Code Playgroud)

但呈现的HTML显示:

<img src="/actives/hotels/13/small/clean_wave.jpg?1317675452" alt="Clean_wave">
Run Code Online (Sandbox Code Playgroud)

为什么"class"属性不存在?

谢谢!

Sim*_*ton 97

必须在括号内分配您的类,以用作要传递的选项的一部分.尝试:

<%= image_tag(iterator.image.url(:small), :class => "img_preview") %>
Run Code Online (Sandbox Code Playgroud)


小智 11

对于像我这样的新手,继承人使用更新的rails语法更清晰:

<%= image_tag iterator.image.url(:small), class:"img_preview" %>
Run Code Online (Sandbox Code Playgroud)