新手问题 Font Awesome 在 rails 中怎么用?

chairy11 · 2013年06月18日 · 最后由 chentianwen 回复于 2013年06月19日 · 4105 次阅读

https://github.com/littlebtc/font-awesome-sass-rails

想要的是链接到"图标+文字",该怎么 用 link_to 写呢?

<%= link_to content_tag('i', nil, class: "icon-white icon-home") + "Index", root_path %>

#1 楼 @miclle 恩,真好,谢谢:)

<%= link_to some_path do %>
  <i class='icon-whatever'></i> text
<% end %>

#4 楼 @ashchan 这个太复杂了,一楼那个貌似就挺好用的。

#5 楼 @chairy11 4 楼这个可读性多好啊

#5 楼 @chairy11 明明是 4 楼的简单,要记住的东西也少啊

#7 楼 @wuwx #8 楼 @swachian 用 content_tag 比#4 楼那样写解析效率略高一点

详见 http://ruby-china.org/topics/6886

slide 42 页

#9 楼 @miclle 要效率干脆

<a href="<%= some_path %>">
  <i class='icon-whatever'></i> text
</a>

我用 slim 是这样写的

a href=(some_path)
  i.icon-whatever
  '
  | text

嗯,我来写的话会写成 #10 那样

应该没有那个 do

#10 楼 @Rei 短的嘛当然可以用用 content_tag,像楼主这种情况;太长了,当然就考虑到编码效率和可读性就用 block 了,

bootstrap_helper 封装成 iButton 了。

#7 楼 @wuwx #8 楼 @swachian 。。。我只是觉得句子少会更简单……我错了……

需要 登录 后方可回复, 如果你还没有账号请 注册新账号