如何在link_to帮助程序中执行<i>标记?</i>

时间:2012-12-27 23:26:55

标签: ruby-on-rails

我想复制一下:

<a href="thepledge.html" class="btn btn-inverse btn-mini btn-ten"><i class="icon-pencil"></i>Take The Pledge</a>  

我试过了:

<%= link_to("Take the pledge", root_path, :class => "btn btn-inverse btn-mini btn-ten")  do %>
   <i class="icon-pencil"></i>
<% end %>

但它给了我这个错误:

NoMethodError at /
undefined method `stringify_keys' for "/":String

link_to来电。

思考?

2 个答案:

答案 0 :(得分:5)

根据documentation,您需要将(完整)链接文本放在块中,如下所示:

<%= link_to(root_path, :class => "btn btn-inverse btn-mini btn-ten")  do %>
   <i class="icon-pencil">Take the pledge</i>
<% end %>

答案 1 :(得分:2)

<%= link_to(root_path, :class => "btn btn-inverse btn-mini btn-ten") do %>
  <i class="icon-pencil"></i>
  Take The Pledge
<% end %>