如何使用 haml 在 rails 上的 link_to 方法中添加很棒的字体?

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

我正在尝试修改我的布局,只是为了将 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 输出:

link_to has a "blocky" form 接受自定义内部标记:

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

关于元素不可见性:元素本身应由 FontAwesome 的 CSS 填充,使用 font-family(在 class fa 上)和 content(在特定图标 class 上)。如果你没有,说明你没有必要的CSS.

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

你可以使用 raw()

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