Search code examples
rubytagseventmachine

How can I add an EM tag to link_to?


I need this output:

<li><a href="#"><em>Name</em><img src="images/9.jpg" alt="image" /></a></li>

and I dont know how to add EM tag to link_to. my code is:

<li><%= link_to image_tag(pic.picture.url(:thumb)), pic, :title => pic.name %></li>

Solution

  • The answer provided by @mbratch is definitely the cleaner way to go, however to answer your specific question you do it like this using the block form of link_to:

    <li>
      <%= link_to pic, title: pic.name do %>
        <em><%= pic.name %></em><%= image_tag(pic.picture.url(:thumb)) %>
      <% end %>
    </li>