2

How do I embed additional HTML inside of a link_to call?

Here is my desired result:

<a href="/exercies/show/1"><i class="icon-show"></i>Show</a>

Here is my link_to call

<%= link_to "Show", exercise_path(exercise) %>
strickland
  • 1,943
  • 5
  • 21
  • 40
  • 3
    I answered this just earlier today! Check out this: http://stackoverflow.com/questions/9401942/using-link-to-with-embedded-html – Veraticus Feb 22 '12 at 21:27

2 Answers2

5
<%= link_to '<i class="icon-search"></i> Show'.html_safe, exercise_path(exercise), :class => 'btn btn-small' %>

.html_safe is required so that it is not escaped.

strickland
  • 1,943
  • 5
  • 21
  • 40
1

It is cleaner if you wrap it in a do block

<%= link_to exercise_path(exercise) do %> <i class="icon-search"></i> Show <% end %>

fzf
  • 931
  • 1
  • 9
  • 19