假设我有这个:
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链接呢?
有没有什么rails方法可以做到这一点?
编辑:解决此问题的块用法如下:
<%= 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>发布于 2012-01-29 01:35:17
这就是解决方案:
<%= 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>希望这能帮助到别人。
https://stackoverflow.com/questions/8960993
复制相似问题