簡體   English   中英

在Rails link_to中添加跨度標簽

[英]Adding span tag in Rails link_to

我已經看過有關如何添加<span>標簽的方法,但是我沒有看到使用Rails 3 link_to<span>放置在我想要的位置的示例:

<a href="#" class="button white"><span id="span">My span&nbsp;</span>My data</a>

我嘗試了類似的東西:

<%= link_to(content_tag{:span => "My span&nbsp;", :id => "span"} @user.profile.my_data, "#", {:class => "button white"}) %>

但這沒有用。

link_to可能會占用一個塊,因此我認為您正在執行以下操作:

<%= link_to '#', :class => 'button white' do %>
    <span id="span">My span&nbsp;</span><%= @user.profile.my_data %>
<% end %>

.html_safe#{@user.profile.my_data}組合也應該起作用。

<%= link_to "<span id='span'>My span&nbsp;</span>#{@user.profile.my_data}".html_safe, "#", class: 'button white' %>

您還可以使用content_tag使其看起來像:

<%= link_to(content_tag(:span, "My span&nbsp;", id:"span")+"#{@user.profile.my_data}", "#", class: 'button white' %> 

它們基本上是相同的,但是對您來說可能會更容易一些。 另外,我對編碼還很陌生,因此,如果由於某種瘋狂的原因而報錯,請發表評論,然后我將其進行更改。 謝謝。

link_to '#', :class => 'button white' do
  <span id="span">My span&nbsp;</span>My data
end

在HAML中:

= link_to  new_post_mobile_path(topic.slug), class: 'add-new-place-btn' do
  %span{:class => "glyphicon glyphicon-plus", :style => "margin-right: 4px;"}
  New Place

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM