How to add class to an image_tag rails helper How to add class to an image_tag rails helper ruby-on-rails ruby-on-rails

How to add class to an image_tag rails helper


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


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

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