如何添加span标签到ruby中的下面的链接?将span标签添加到ruby链接?
<%= link_to (l(:button_show), {:action => 'show', :path => to_path_param(@path)}, :class => "button") %>
我想跨度标签添加到像这样的链接:
<a href="/show" class="button"><span>Show</span></a>
如何添加span标签到ruby中的下面的链接?将span标签添加到ruby链接?
<%= link_to (l(:button_show), {:action => 'show', :path => to_path_param(@path)}, :class => "button") %>
我想跨度标签添加到像这样的链接:
<a href="/show" class="button"><span>Show</span></a>
完全可能的。到link_to
第一个参数是任意的字符串,那么你可以这样做:
<%= link_to("<span>#{l(:button_show)}</span>",
{:action => 'show', :path => to_path_param(@path)}, :class => "button") %>
由于link_to
可以采取块的名称,不过,一个更可读的方式可能做到这一点:
<% link_to({:action => 'show', :path => to_path_param(@path)}, :class => "button") do %>
<span><%= l(:button_show) %></span>
<% end %>
Kevin's answer会正常工作。我更喜欢他的第二个选择(使用块)将插入的字符串作为参数。我可能更喜欢这个:
<%= link_to content_tag(:span, l(:button_show)), {:action => 'show', :path => to_path_param(@path)}, :class => "button" -%>
content_tag
只是返回一个HTML字符串。它的第一个参数是标签的名称。第二个是标签内容。 (有一个替代块的用法,但这只会使事情复杂化。)
这甚至有可能吗? – amy 2010-01-08 01:11:45