samedi 6 octobre 2018

How do I write a simple if statement to check if the current user has already reviewed something?

In the view I have tried everything. Currently I have:

Leave a Review

  <% if current_user.reviews.include?(@book) %>
  <p>You've already reviewd this</p>
  <% else %>
    <div id="review-links">
      <%= link_to "write a review", new_book_review_path(@book.id) %>
    </div>
  <% end %>
<% end %>

Unfortunately I still have the link showing to leave a review on the book's show page even though the reviewer has already written one for that book. What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire