2011-04-08 86 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