コードは次のとおりです。
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
一見すると、管理者ロールを持つユーザーは、 のため、Web サイト コントローラーで何でもできるはずですcan :manage, :all
。
しかし、ウェブサイト/インデックスにアクセスすると、
CanCan::AccessDenied in WebsitesController#index
You are not authorized to access this page.
なぜこうなった?