簡體   English   中英

rails cancan gem,可以在capability.rb中使用的方法

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM