tva*_*nt2 34 html ruby-on-rails link-to ruby-on-rails-3
我已经看过如何添加<span>标签但是我没有看到<span>使用Rails 3 放置我想要的位置的示例link_to:
<a href="#" class="button white"><span id="span">My span </span>My data</a>
Run Code Online (Sandbox Code Playgroud)
我尝试过类似的东西:
<%= link_to(content_tag{:span => "My span ", :id => "span"} @user.profile.my_data, "#", {:class => "button white"}) %>
Run Code Online (Sandbox Code Playgroud)
但那没用.
mu *_*ort 83
link_to可以采取一个块,所以我认为你是这样的:
<%= link_to '#', :class => 'button white' do %>
<span id="span">My span </span><%= @user.profile.my_data %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
结合.html_safe使用也#{@user.profile.my_data}应该有效.
<%= link_to "<span id='span'>My span </span>#{@user.profile.my_data}".html_safe, "#", class: 'button white' %>
Run Code Online (Sandbox Code Playgroud)
你也可以使用content_tag它看起来像:
<%= link_to(content_tag(:span, "My span ", id:"span")+"#{@user.profile.my_data}", "#", class: 'button white' %>
Run Code Online (Sandbox Code Playgroud)
它们基本相同,但对你来说可能更容易.另外,我对编码很新,所以如果出于某种疯狂的原因这是错误的,请注释,我会改变它.谢谢.
link_to '#', :class => 'button white' do
<span id="span">My span </span>My data
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28700 次 |
| 最近记录: |