user2993454
user2993454

Reputation: 220

Rails: how to use fontawesome icon

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?' } %> 

Upvotes: 4

Views: 6200

Answers (2)

alex
alex

Reputation: 644

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 %>

Upvotes: 3

joseramonc
joseramonc

Reputation: 1931

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.

Upvotes: 14

Related Questions