Fintan Moloney
Fintan Moloney

Reputation: 5

Rails: how do I add a class to this image src code? Putting div tags around it didn't work

<% if item.image.attached? %>
    <image src="<%=(url_for(item.image), :class => "itemholsIm") %>">
<% end %>

How should it be done?

Upvotes: 0

Views: 210

Answers (3)

Nicolas Iniesta
Nicolas Iniesta

Reputation: 26

Yes, the rails img_tag helper is the best solution !

Upvotes: 0

NeK
NeK

Reputation: 866

You can use img_tag helper.

<%= image_tag(item.image, class: "itemholsIm") %>

Upvotes: 2

Nicolas Iniesta
Nicolas Iniesta

Reputation: 26

You have to put the CSS class out of the <%= %>

Try this :

<% if item.image.attached? %>
    <image src="<%=(url_for(item.image)%>" class="itemholsIm">
<% end %>

Upvotes: 1

Related Questions