如何使用haml在rails上为link_to方法添加字体真棒?

时间:2015-10-22 08:53:22

标签: ruby-on-rails ruby ruby-on-rails-4 haml font-awesome

我正在尝试修改我的布局,只是为了将link_to添加到我的下拉列表中。

上一个代码:

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

我这样编辑:

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

一切看起来都很好,但是fa-user-profile是0px x 0px并且它是不可见的。我做错了什么?

Html输出:

enter image description here

2 个答案:

答案 0 :(得分:5)

接受自定义内部标记的

link_to has a "blocky" form

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

关于元素不可见性:元素本身应该由FontAwesome的CSS填充,使用font-family(在类fa上)和content(在特定的图标类上)。如果你没有,那就意味着你没有必要的CSS。

如何添加它取决于FontAwesome集成到资产管道中的方式。 font-awesome-sass' README对此有非常明确的指示,您的解决方案可能会有所不同。

答案 1 :(得分:1)

您可以使用raw()

= link_to raw('<i class="fa fa-user-profile"></i> Add new user'), new_user_path