ruby-on-rails - 来宾用户的 Cancancan 功能
问题描述
网站有模型帖子,它只显示一个帖子,没什么特别的
def initialize(user)
can :manage, Post
end
这有效,但当然应该是
def initialize(user)
can :read, Post
end
哪个不起作用 (403)
根据我读过的内容:read should alias for index show actions 我找不到调试失败原因的方法。所有帮助表示赞赏
解决方案
我想您正在使用方法自动授权 RESTful 样式资源控制器中的所有操作load_and_authorize_resource
。如果该index
操作不需要用户登录,那么您应该跳过此方法专门用于index
. 尝试
load_and_authorize_resource :except => [:index]
推荐阅读
- google-analytics - gtag.js 的自然搜索源
- r - 如何全屏显示图形?
- java - 最小化窗口时如何阻止摆动从窗口中删除所有内容?
- java - Gradle 确定在构建时运行哪些单元测试
- python - 如何知道其他人的Django项目使用的python包版本并相应地安装它们?
- python - 如何在 sqlalchemy 中使用特定数字启动主键?
- flutter - 当我的 ListView 在展开时出现 RenderBox 错误
- javascript - 如何将图像设置为所有
- tensorflow - 如果 D-Drive 中安装了 anaconda,如何使用 TensorFlow GPU?
- c# - 如何比较具有相同属性的两个视图模型,如果属性的值不同,则将该属性添加到不同的列表中?