Sri
Sri

Reputation: 2273

rails add image inside the map method

I have a link separated by comma in my view like the following:

<%= raw post.tag_list.map { |t| link_to t, tag_path(t) }.join(' ') %>

I want the image_tag instead of string.

For example, I got the result:

Book, Sports, World

Instead of the above links of String I want to show the image of Book, image of Sports, image of world.

How can I achieve in rails. Thanks

Upvotes: 0

Views: 168

Answers (1)

Thomas Klemm
Thomas Klemm

Reputation: 10856

I think you're looking for something along the lines of

<% post.tag_list.each do |tag| %>
  <%= link_to image_tag(tag.image_url), tag_path(tag) %>
<% end %>

Upvotes: 1

Related Questions