如何向image_tag rails助手添加类?

时间:2021-12-18 00:27:19

I have the following code:

我有以下代码:

<%= image_tag iterator.image.url(:small), :class => "img_preview" %>

But the rendered HTML shows:

但呈现的HTML显示:

<img src="/actives/hotels/13/small/clean_wave.jpg?1317675452" alt="Clean_wave">

Why the "class" attribute isn't there?

为什么不存在“class”属性?

Thank you!

谢谢你!

2 个解决方案

#1


85  

Your class has to be assigned inside of the brackets to be used as part of the options being passed through. Try:

您的类必须被分配到括号内,以作为传递的选项的一部分。试一试:

<%= image_tag(iterator.image.url(:small), :class => "img_preview") %>

#2


7  

For newbies like myself, heres a cleaner version with the newer rails syntax:

对于像我这样的新手,这里有一个更干净的版本,具有更新的rails语法:

<%= image_tag iterator.image.url(:small), class:"img_preview" %>

#1


85  

Your class has to be assigned inside of the brackets to be used as part of the options being passed through. Try:

您的类必须被分配到括号内,以作为传递的选项的一部分。试一试:

<%= image_tag(iterator.image.url(:small), :class => "img_preview") %>

#2


7  

For newbies like myself, heres a cleaner version with the newer rails syntax:

对于像我这样的新手,这里有一个更干净的版本,具有更新的rails语法:

<%= image_tag iterator.image.url(:small), class:"img_preview" %>