[英]rails cancan gem,, can method in ability.rb how to use
我使用的是康康宝石,但我有些困惑。 有什么区别:
can :read, Post
can :read, :post
can :read, @post
什么是更好(安全)的方式?
can :read Post
表示用户可以阅读任何帖子,因为它通常引用模型
can :read @post
can :read :post
表示用户可以阅读该特定帖子(通常是因为该帖子与该用户或类似内容具有belongs_to关联)
有关如何设置能力页面的示例:
if user.admin?
can :read Post #admin can read any post
else
can :read Post, :user_id => user.id #non-admins can read only posts that belong to them.
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.