Rails link_to带有样式glyphicon的标记标记

我正在尝试使用我在rails应用程序中设置样式的字形图标。

我想让图标成为另一个页面的链接,但不能使用标准的引导程序样式,因为我已经为我的页面样式定制了链接。

我一直收到关键字类错误 – 有谁知道为什么?

谢谢。

我的观点中有以下链接:

  • <%= link_to , page_path('messages') %>
  • 我也有css如下:

     span.glyphicon-comment { vertical-align:middle; margin:auto; padding:10px; font-size: 2em; text-align: right; a:link {text-decoration:none; background-color:transparent; color:grey;}; a:visited {text-decoration:none;background-color:transparent; color:grey;}; a:hover {text-decoration:none;background-color:transparent; color:dark grey;}; a:active {text-decoration:none;background-color:transparent; color:grey;}; } 

    你必须使用“围绕字符串,还需要调用html_safe方法。

     <%= link_to "".html_safe, page_path('messages') %> 

    但是更好更清洁的方式

     <%= link_to page_path('messages') do %>  <% end %> 

    你的问题是你使用的a:visited {text-decoration:none; background-color:transparent; color:grey;}; a:visited {text-decoration:none; background-color:transparent; color:grey;}; 在你的glyphicon css上,但它们应该在你的链接上

    试试这个:

     <%= link_to page_path('messages'), class: "comment_link" do %>  <% end %> 

    然后设置你的链接样式,如果你使用scss那么:

     .comment_link{ .glyphicon-comment{ vertical-align:middle; margin:auto; padding:10px; font-size: 2em; text-align: right; } &:hover, &:visited, &:active{ text-decoration:none; background-color:transparent; color:dark grey; } }