本人是一个新手,最近尝试使用 cancancan 做权限等级设置,代码写完后,在本地运行通过了,但是部署到服务器上面之后,项目不能正常运行,查看 log 的时候发现提示这个错误,undefined local variable or method `authorize_resource' for AdminController:Class (NameError),请求大神帮帮忙。
class AdminController < ApplicationController
authorize_resource
rescue_from CanCan::AccessDenied do |exception|
if request.env["HTTP_REFERER"] == nil
redirect_to admin_activities_path, :alert => exception.message
else
redirect_to request.env["HTTP_REFERER"], :alert => exception.message
end
end
def current_ability
@current_ability = Ability.new(current_user)
end
end
class Ability
include CanCan::Ability
def initialize(user)
if user.username == "admin"
can :manage, :all
else
can :manage, Activity
end
end
end