未初始化的常量ApplicationController :: CanCan(NameError)

时间:2013-08-14 01:06:19

标签: ruby-on-rails ruby-on-rails-3 heroku cancan

我的应用程序在开发环境中正常运行,但是当我尝试运行>时出现以下错误rails server -e production 我已经搜索了这个,我找到了关于重启独角兽的答案,但我的应用程序中没有独角兽,我该怎么办才能解决它?

/app/controllers/application_controller.rb:6:in `<class:ApplicationController>': uninitialized constant ApplicationController::CanCan (NameError)
from /home/dexter/Desktop item/Triton/app/controllers/application_controller.rb:1:in `<top (required)>'
from /var/lib/gems/1.9.1/gems/ckeditor-4.0.4/app/controllers/ckeditor/application_controller.rb:1:in `<top (required)>'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:439:in `block (2 levels) in eager_load!'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:438:in `each'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:438:in `block in eager_load!'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:436:in `each'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:436:in `eager_load!'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/application/railties.rb:8:in `each'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/application/railties.rb:8:in `all'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:434:in `eager_load!'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/application/finisher.rb:53:in `block in <module:Finisher>'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `instance_exec'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `run'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:55:in `block in run_initializers'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `each'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `run_initializers'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/application.rb:136:in `initialize!'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/dexter/Desktop item/Triton/config/environment.rb:5:in `<top (required)>'
from /home/dexter/Desktop item/Triton/config.ru:3:in `block in <main>'
from /var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
from /var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
from /home/dexter/Desktop item/Triton/config.ru:in `new'
from /home/dexter/Desktop item/Triton/config.ru:in `<main>'
from /var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
from /var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
from /var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands/server.rb:46:in `app'
from /var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
from /var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands/server.rb:70:in `start'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:55:in `block in <top (required)>'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:50:in `tap'
from /var/lib/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

我的应用程序控制器:

class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :authenticate_user!


  rescue_from CanCan::AccessDenied do |exception|
    flash[:error] = exception.message
    redirect_to root_path
  end

  private
  def stored_location_for(resource_or_scope)
    nil
  end

  def after_sign_in_path_for(resource_or_scope)
    '/dashboard'
  end



end

Gemfile&gt;刚刚发布了CanCan的地方

group :assets do
  gem 'cancan'

end

1 个答案:

答案 0 :(得分:1)

从Gemfile中的资产组中删除cancan。资产组是不在生产中使用的宝石。因此,当您在生产模式下运行应用程序时,资产块中的gem将被排除。