开发者

Rails - CanCan - accessible_by

开发者 https://www.devze.com 2023-02-11 14:47 出处:网络
Can anyone explain to me how CanCan\'开发者_如何转开发s accessible_by works?How does it know what the relationship is between the user and the thing that needs restricting?It checks the current user a

Can anyone explain to me how CanCan'开发者_如何转开发s accessible_by works? How does it know what the relationship is between the user and the thing that needs restricting?


It checks the current user against a set of rules described in the abilities initializer which includes CanCan::Ability. When you call accessible_by it checks the rules specifed in the Ability class, and returns the records that the user has access to.
The gem's wiki is very good... here: defining abilities


There is a great railscast about CanCan (made by its creator):

http://railscasts.com/episodes/192-authorization-with-cancan

0

精彩评论

暂无评论...
验证码 换一张
取 消