content01
content01

Reputation: 3225

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!

Upvotes: 53

Views: 93367

Answers (2)

Brandon LoGuercio
Brandon LoGuercio

Reputation: 171

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

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

Upvotes: 17

Simpleton
Simpleton

Reputation: 6415

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

Upvotes: 117

Related Questions