无法在我的演示 rails 应用中创建或销毁对产品的评论

Cannot create nor destroy comments to a product in my demo rails app

我正在学习Rails并且我有一个要开发的演示应用程序,我在其上安装了 Devise 和 CanCanCan 以进行身份​​验证和授权。 我有一些产品,我刚刚添加了评论功能。 如果我评论一个产品,它不会让我创建一个,出现 "You are not authorized to access this page" 错误,然后它将我重定向到我的第一页 (landing_page)。我在尝试删除评论时遇到了同样的问题。 (评论已设置为产品的嵌套资源) 以下是我使用的评论视图

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

这也是我的linkgithubhttps://github.com/Adsidera/FreshObst

我在路线上一头雾水,我无法弄清楚错误在哪里,无论是在产品中,还是在评论控制器中,或者这是一个 routes.rb 问题。非常感谢! 安娜

我刚刚逐步复习了我所学的课程,并且可以解决该问题。现在我可以添加评论了,评论也显示出来了,我也可以销毁评论了..