问题描述
我是 Ruby 的初学者,我对此疑惑了好几个小时。如何将 "link_to"
放在整张卡片下?我有这个代码:
<div class = "card-body">
<h4> <% = link_to post.title,post%> </h4>
<div class = "text-muted mb-2">
<em> By <% = post.author%> (<% = l (post.created_at,format:: long)%>) </em>
</div>
<p> <% = post.body.truncate (220)%> </p>
<p class = "text-muted"> <% = pluralize (post.comments.count,'Comment')%> </p>
</div>
并希望 "card-body"
类用作 "link_to"
解决方法
您可以将块传递给 link_to
方法。
<%= link_to post do %>
<div class="card-body">
<h4><%= post.title %></h4>
...
</div>
<% end %>