首页 > 解决方案 > 来宾用户的 Cancancan 功能

问题描述

网站有模型帖子,它只显示一个帖子,没什么特别的

def initialize(user)    
        can :manage, Post
end

这有效,但当然应该是

def initialize(user)    
        can :read, Post
end

哪个不起作用 (403)

根据我读过的内容:read should alias for index show actions 我找不到调试失败原因的方法。所有帮助表示赞赏

标签: ruby-on-railscancancan

解决方案


我想您正在使用方法自动授权 RESTful 样式资源控制器中的所有操作load_and_authorize_resource。如果该index操作不需要用户登录,那么您应该跳过此方法专门用于index. 尝试

load_and_authorize_resource :except => [:index]


推荐阅读