Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add class to an image_tag rails helper

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!

like image 831
content01 Avatar asked Nov 25 '11 19:11

content01


2 Answers

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") %>
like image 133
Simpleton Avatar answered Oct 20 '22 06:10

Simpleton


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

<%= image_tag iterator.image.url(:small), class:"img_preview" %>
like image 26
Brandon LoGuercio Avatar answered Oct 20 '22 06:10

Brandon LoGuercio