2

I am a beginner in Ruby and I am in this doubt for many hours. how to put "link_to" under an entire card? I have this code:

<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>

and wanted the "card-body" class to function as the "link_to"

jamal
  • 65
  • 6

1 Answers1

3

You can pass a block to the link_to method.

<%= link_to post do %>
  <div class="card-body">
    <h4><%= post.title %></h4>
    ...
  </div>
<% end %>
Arun Kumar Mohan
  • 11,517
  • 3
  • 23
  • 44