Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add font awesome to link_to method on rails using haml?

I am trying to modify my layout just to add link_to to my drop down list.

previous code:

  %li.divider
  %li
    %a{:href => "#"}
      %i.fa.fa-user-profile
      Add new user

i edited like this:

 %li.divider
 %li
   = link_to '<i class="fa fa-user-profile"></i> Add new user'.html_safe, new_user_path

And everything looks fine, but fa-user-profile is 0px x 0px and it is invisible. What i done wrong?

Html output:

enter image description here

like image 230
Titas Kurtinaitis Avatar asked Oct 22 '15 08:10

Titas Kurtinaitis


1 Answers

link_to has a "blocky" form that accepts custom inner markup:

= link_to new_user_path do
  %i.fa.fa-user-profile
  Add new user

Regarding element invisibility: the element itself should be filled in by FontAwesome's CSS, using font-family (on class fa) and content (on specific icon class). If you don't have them, it means you don't have the necessary CSS.

How to add it, depends on the way FontAwesome is integrated into your asset pipeline. font-awesome-sass' README has pretty clear instructions on that, your solution's might differ.

like image 60
D-side Avatar answered Sep 28 '22 06:09

D-side