带有样式字形的 Rails link_to 标记 [英] Rails link_to tag tag with styled glyphicon
本文介绍了带有样式字形的 Rails link_to 标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用我在 Rails 应用中设计的字形图标.
I am trying to use glyph icons that I have styled in my rails app.
我想让图标成为另一个页面的链接,但不能使用标准的引导程序样式,因为我已经为我的页面样式自定义了链接.
I want to make the icon a link to another page, but can't use the standard bootstrap styling because I have customised the links for my page's style.
我不断收到关键字类错误 - 有谁知道为什么?
I keep getting a keyword class error - does anyone know why?
谢谢.
我认为有以下链接:
<li><%= link_to <span class="glyphicon glyphicon-comment"></span>, page_path('messages') %> </li>
我也有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
方法.
You have to use "
around the string, also need to call html_safe
method on it.
<%= link_to "<span class=\"glyphicon glyphicon-comment\"></span>".html_safe, page_path('messages') %>
但更好、更干净的方法是
but a better and cleaner way would be
<%= link_to page_path('messages') do %>
<span class="glyphicon glyphicon-comment"></span>
<% end %>
这篇关于带有样式字形的 Rails link_to 标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文