mardi 24 novembre 2015

link_to Show page takes me to the index page Rails?

I am trying to have a dashboard in my app that lists all the reviews the user has. The problem that i have is when i click on the post that the user gave a review in , it takes me to the index page of all the posts instead of the show page of the specific post. This is the line of code i am having issue with <td><%= link_to review.post.title , posts_path(@post) %></td> . Here's my code:

views/pages/dashboard.html.erb

<div class="align-left">



<div class="col-md-2">
<h5><%= @user.name %></h5>


</div>
<div class="col-md-5">
<h3>My Posts</h3>

<table class="table table-hover">
      <thead>
        <tr>
          <th>Name</th>
          <th>Created</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
      <% @posts.each do |post| %>
        <tr>
          <td><%= post.title %></td>
          <td><%= time_ago_in_words(post.created_at) %> ago</td>
          <td><%= link_to "Edit", edit_post_path(post) %>|<%= link_to "Destroy", post_path(post), method: :delete %></td>
        </tr>
      <% end %>
      </tbody>
    </table>

</div>

<br>

<h3>My Reviews</h3>
<table class="table table-hover">
      <thead>
        <tr>
          <th>Place</th>
          <th>Created</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
      <% @reviews.each do |review| %>
        <tr>
         <td><%= link_to review.post.title , posts_path(@post) %></td> 
        <td><%= time_ago_in_words(review.created_at) %> ago</td>
        </tr>
      <% end %>
      </tbody>
    </table>
</div>

</div>

the Rake route file

enter image description here

Aucun commentaire:

Enregistrer un commentaire