我是 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”
最佳答案
您可以将一个 block 传递给 link_to
方法。
<%= link_to post do %>
<div class="card-body">
<h4><%= post.title %></h4>
...
</div>
<% end %>
关于html - 如何将 "link_to"放在整张卡下?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66757188/