1
以下是代碼。CanCan + Devise:管理員用戶無法獲得權限,即使他應該
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.
這究竟是爲什麼?
嗨!你是否在用「rolify」來管理用戶的角色? – jvnill 2013-03-28 00:50:16
@jvnill,我解決了我的問題。它在下面的答案中看到了我的愚蠢錯誤。 – 2013-03-28 00:51:25