2012-01-22 56 views
0

讓我們說我有這樣的:如何顯示其中的html標籤鏈接html代碼?

link_to "Profile", profile_path(@profile) 

# => <a href="/profiles/1">Profile</a> 

但如果我只需要像<a href="/profiles/1"><h1>Title</h1><p>some text</p></a>的HREF鏈接?

有沒有這樣做的軌道方法?

編輯:Soluction因爲這是塊使用這樣的:

<%= link_to(@profile) do %> 
<strong><%= @profile.name %></strong> -- <span>Check it out!</span> 
<% end %> 
# => <a href="/profiles/1"> 
    <strong>David</strong> -- <span>Check it out!</span> 
</a> 
+0

link_to「」,profile_path(@profile)也許? –

+0

對不起,我不得不編輯,以確切地問​​我在找什麼。 –

+0

剛剛發現有關使用塊的文檔。謝謝! –

回答

0

這是解決方案:

<%= link_to(@profile) do %> 
<strong><%= @profile.name %></strong> -- <span>Check it out!</span> 
<% end %> 
# => <a href="/profiles/1"> 
<strong>David</strong> -- <span>Check it out!</span> 
</a> 

希望它可以幫助別人。