jeudi 14 mars 2019

NoMethodError when trying to view post as another user

Users can leave reviews for a post in my rails app, if I leave a review on a post as the current_user and view the review on the post-show page I don't get any errors, but I get "NoMethodError undefined method `username' for nil:NilClass" if I'm signed in as another user and try to see the other review left on that post.

<p> Posted by <%= review.user.username %> </p>
<p><%= review.comment %></p>
</div>
</div>

<% if user_signed_in? %>

<% if review.user_id == current_user.id %>

<%= link_to "Edit", edit_post_review_path(review.post, review) %>
<%= link_to "Delete", post_review_path(review.post, review),method: :delete, data: { confirm: "Are you sure you want to permanently delete your review?"} %>

Aucun commentaire:

Enregistrer un commentaire