How to add class to an image_tag rails helper

content01 picture content01 · Nov 25, 2011 · Viewed 80.7k times · Source

I have the following code:

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

But the rendered HTML shows:

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

Why the "class" attribute isn't there?

Thank you!

Answer

Simpleton picture Simpleton · Nov 26, 2011

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") %>