Rails - CanCan -accessible_by
谁能向我解释一下 CanCan 的 accessible_by
是如何工作的?它如何知道用户和需要限制的事物之间的关系是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它根据能力初始值设定项中描述的一组规则检查当前用户,其中包括
CanCan::Ability
。当您调用accessible_by
时,它会检查Ability
类中指定的规则,并返回用户有权访问的记录。gem 的 wiki 非常好...这里:定义能力
It checks the current user against a set of rules described in the abilities initializer which includes
CanCan::Ability
. When you callaccessible_by
it checks the rules specifed in theAbility
class, and returns the records that the user has access to.The gem's wiki is very good... here: defining abilities
有一个关于 CanCan 的很棒的railscast(由其创建者制作):
http://railscasts.com /episodes/192-authorization-with-cancan
There is a great railscast about CanCan (made by its creator):
http://railscasts.com/episodes/192-authorization-with-cancan