I am studying Rails and I have a demo app to develop, on which I installed Devise and CanCanCan for authentication and authorization. I have some Products and I just added the comments functionality. If I comment a product, it won't let me create one, an error appears with "You are not authorized to access this page" and then it redirects me to my first page (landing_page). I have the same issue when trying to delete a comment. (Comment has been set as a nested resource of product) The following is the comments view I am using
<div class="product-reviews">
<% @comments.each do |comment| %>
<div class="row" style="padding-left:4%;">
<HR>
<p><small><%= comment.user.email %><em><%= " #{time_ago_in_words(comment.created_at)} ago" %></em></small></p>
<div class="rated" data-score="<%= comment.rating %>"></div>
<p><%= comment.body %></p>
<% if signed_in? && current_user.admin? %>
<p><%= link_to 'Destroy', product_comment_path( @product, comment), method: :delete, data: { confirm: 'Are you sure?'} %></p>
<% end %>
</div>
<% end %>
This is also the link to my github https://github.com/Adsidera/FreshObst
I am hitting my head on the routes and I cannot figure out where the mistake is, whether in the products, or comments controller or it is a routes.rb issue. Thanks a lot in advance! Anna