Gem cancancan 在引用的时候出现 undefined local variable or method `authorize_resource' for AdminController:Class (NameError)

kevin_he · 2016年02月01日 · 最后由 killernova 回复于 2016年02月01日 · 2249 次阅读

本人是一个新手,最近尝试使用 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

Gemfile贴一下

我猜是没重启服务?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号