2011-04-08 42 views
23

在Rails中使用link_to助手時,如何向鏈接添加其他內容?link_to在定位標記內附加html

link_to "Stephen Weber", "index.html" 

創建此:

<a href="index.html">Stephen Weber</a> 

但是,如果我想要創建這個?

<a href="index.html"> 
    <h3>Stephen Weber</h3> 
    <p><strong>You've been invited to a meeting at Filament Group in Boston, MA</strong></p> 
    <p>Hey Stephen, if you're available at 10am tomorrow, we've got a meeting with the jQuery team.</p> 
    <p class="ui-li-aside"><strong>6:24</strong>PM</p> 
</a> 

我玩弄jQuery Mobile的,這就是需要在列表格式內容。

回答

52

你可以這樣做:

<%= link_to 'index.html', :title => "Some link" do %> 
    <h3> Stephen Weber </h3> 
    ... 
<% end %> 
+2

謝謝。我覺得很愚蠢。我忘了你可以通過一個街區。我最終會學習這些東西,特別是在社區的支持下! – 2011-04-08 18:49:48

+0

別擔心,這是學習曲線的一部分! – konus 2011-04-08 21:02:32

+1

我不得不將「<%= link_to」更改爲「<%link to」以避免編譯錯誤,僅供參考。 – theschmitzer 2011-11-18 12:45:01