4

I want to add fontawesome icon

<i class="fa fa-trash-o"></i> 

in place of "Destroy"

<%= link_to 'Destroy', post_path(post), method: :delete, data: { confirm: 'Are you sure?' } %> 
2

2 Answers 2

14

You can try

<%= link_to(
      content_tag(
        :i,
        nil, 
        class: 'fa fa-trash-o'
      ), 
      method: :delete, 
      data: { 
        confirm: 'Are you sure?' 
      } 
    ) 
%>

You can try with other things that aren't :i like :div and if you want text inside like <i>TEXT</i> you can try with the TEXT instead of nil, hope this helps you.

1
  • 1
    Great suggestion to use nil in the content_tag. <i>TEXT</i> works too but gives italic TEXT. I was able to get text plus an icon with link_to title.html_safe + content_tag(:i, nil, :class => ...). If you're using the font-awesome-rails gem, the fa_icon helper is another option; see github.com/bokmann/font-awesome-rails.
    – Mark Berry
    Feb 26, 2014 at 3:35
3

you can also use a block like so

<%= link_to post_path(post), method: :delete, data: { confirm: 'Are you sure?' } do %>
    <i class="fa fa-trash-o"></i> 
<% end %>
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.