简体   繁体   English

来宾用户的 Cancancan 能力

[英]Cancancan ability for guest user

Site is having model Post which just display a Post, nothing fancy If in Ability i add When no user is logged it they should be able to read all the post So in Ability.rb网站有模型帖子,它只显示一个帖子,没什么特别的

def initialize(user)    
        can :manage, Post
end

This works but of course it should be这有效,但当然应该是

def initialize(user)    
        can :read, Post
end

Which doesn't work (403)哪个不起作用 (403)

Based on what I've read :read should alias for index show actions I can't find a way to debug why it fails.根据我读过的内容 :read should alias for index show actions 我找不到调试失败原因的方法。 All help appreciated所有帮助表示赞赏

I suppose you are automatically authorizing all actions in a RESTful style resource controller with load_and_authorize_resource method.我想您正在使用load_and_authorize_resource方法自动授权 RESTful 样式资源控制器中的所有操作。 If the index action does not require user to login then you should skip this method specifically for index .如果index操作不需要用户登录,那么您应该专门针对index跳过此方法。 Try尝试

load_and_authorize_resource :except => [:index]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM