簡體   English   中英

無法使用Cancan授予對自定義操作的訪問權限

[英]Unable to give access to custom action using cancan

我有Blog Controller和Model,我想授予對自定義操作的訪問權限,我的能力模型如下所示:

user ||= User.new # guest user (not logged in)
  if user.has_role? :admin
    can :manage, :all
  elsif user.has_role? :creator
    can :progress, Blog
    can :read, :all
    can :manage, Blog
  else 
    can :read, :all
  end

在我的進度操作中,我正在授權這樣的用戶

authorize! :progress, current_user

但這總是給我授權用戶錯誤。

You are not authorized to access this page.

您的能力文件看起來不錯,除了“ manage”代表全部,因此can:progress,Blog like已完全覆蓋can:manage,Blog行

授權! 但是,在您的進度操作中調用不應將current_user作為第二個參數,而是要檢查其訪問權限的對象,例如@blog或類似的對象

請查看https://github.com/ryanb/cancan/wiki/authorizing-controller-actions了解更多詳細信息!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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