Ray
Ray

Reputation: 349

Dynamically passing class name

<ul>
  <% @pages.situations.each do |situation| %>
    <li class="<%= situation %>">
      <%= image_tag('image/"<%situation%>".png') %>
    </li>
  <% end %>
</ul>

I want to pass the images name dynamically in rails. Basically, my lists, image and class names are the same so I tried to do like something above. It doesn't work. Would really appreciate your help guys. Thanks

Upvotes: 0

Views: 41

Answers (1)

Mohammad AbuShady
Mohammad AbuShady

Reputation: 42919

Your interpolation is not done correctly, try something like this

<%= image_tag("image/#{situation}.png") %>

Upvotes: 2

Related Questions