Using link_to with embedded HTML
Solution 1:
Two ways. Either:
<%= link_to user_path(@user) do %>
<i class="icon-ok icon-white"></i> Do it@
<% end %>
Or:
<%= link_to '<i class="icon-ok icon-white"></i> Do it@'.html_safe, user_path(@user) %>
Solution 2:
I had the same need recently. Try this:
<%= link_to '<i class="icon-ok icon-white"></i> Do it'.html_safe, user_path(@user) %>
Solution 3:
You have also the possibility to create an helper method like below:
def link_fa_to(icon_name, text, link)
link_to content_tag(:i, text, :class => "fa fa-#{icon_name}"), link
end
Adapt the classes to your needs.
Solution 4:
If you want a link in rails that uses that same icon class from twitter bootstrap all you need to do is something like this.
<%= link_to "Do it@", user_path(@user), :class => "btn icon-ok icon-white" %>