这是代码。
class WebsitesController < ApplicationController
load_and_authorize_resource
...
end
class ApplicationController < ActionController::Base
...
check_authorization :unless => :do_not_check_authorization?
private
def do_not_check_authorization?
respond_to?(:devise_controller?)
end
end
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
if user.role? == "admin"
can :manage, :all
elsif user.role? == "developer"
can :manage, :websites
can :manage, :pages
can :manage, :templates
elsif user.role? == "editor"
can :manage, :pages
end
end
end
从外观上看,具有管理员角色的用户应该能够使用网站控制器做任何事情,因为
can :manage, :all
.
但当我访问网站/索引时,我会
CanCan::AccessDenied in WebsitesController#index
You are not authorized to access this page.
为什么会发生这种情况?