ExceptionNotifier常量未初始化Rails 3
我已阅读了本网站上的许多问题以及ExceptionNotifier的GitHub文档及其在Rails 3中的实现,并且我无法弄清楚为什么它对我无效生产服务器。在我的本地计算机(Mac)上,它可以在生产环境中正常工作。但是当我用capistrano部署并在Linux机器上使用独角兽运行应用程序后,我的独角兽日志在我的environments/production.rb文件中抱怨uninitialized constant ExceptionNotifier
,尽管我的本地机器似乎认为它没问题。我试过两种实现: gem 'exception_notification', :require => 'exception_notifier'
和 gem 'exception_notification_rails3', :require => 'exception_notifier'
。两者都抛出这个错误。这里是我的production.rbExceptionNotifier常量未初始化Rails 3
Rl4::Application.configure do
# code omitted
# Enable ExceptionNotifier, having it ignore its default exceptions
config.middleware.use ExceptionNotifier,
sender_address: '[email protected]',
exception_recipients: '[email protected]',
ignore_exceptions: ExceptionNotifier.default_ignore_exceptions
end
这里是我的Gemfile
source 'https://rubygems.org'
# lots omitted
gem 'exception_notification_rails3', :require => 'exception_notifier'
# lots more omitted
这是我的application_controller.rb,它实现了创业板:
class ApplicationController < ActionController::Base
protect_from_forgery
# By default, only production ENV considers requests not local
unless Rails.application.config.consider_all_requests_local
rescue_from Exception, :with => :server_error
rescue_from ActionController::UnknownAction, :with => :not_found
rescue_from ActionController::UnknownController, :with => :not_found
rescue_from ActionView::MissingTemplate, :with => :not_found
end
private
def server_error(exception)
ExceptionNotifier::Notifier.exception_notification(request.env, exception).deliver
respond_to do |format|
format.html { render template: '/500.html', layout: 'application/layout', status: 500 }
format.all { render nothing: true, status: 500 }
end
end
def not_found(exception)
ExceptionNotifier::Notifier.exception_notification(request.env, exception).deliver
respond_to do |format|
format.html { render template: '/404.html', layout: 'application/layout', status: 404 }
format.all { render nothing: true, status: 404 }
end
end
end
再次,执行是不是我的问题在这一刻。不知何故,该宝石没有正确安装或未正确初始化。我确实在两个版本的gem的Linux机器上运行了sudo gem install,以及'exception_notifier'。没有骰子。思考?
其他信息 我只是试图重新安装宝石作为一个插件,并改变production.rb文件来使用,而不是config.middleware.use ::ExceptionNotifier
后得到了同样的错误。但是,这些修改仍然适用于我的本地机器。也许我错过了Linux机器上的另一个软件?似乎没有任何
我使用exception_notification,诉3.0.1
获取完整的堆栈跟踪的文件上提到...
申请宝石版本
I, [2013-04-24T17:34:44.113788 #16877] INFO -- : Refreshing Gem list
E, [2013-04-24T17:34:46.562588 #16877] ERROR -- : uninitialized constant ExceptionNotifier (NameError)
/home/deployer/rl4/releases/20130424201053/config/environments/production.rb:80:in `block in <top (required)>'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:24:in `class_eval'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:24:in `configure'
/home/deployer/rl4/releases/20130424201053/config/environments/production.rb:1:in `<top (required)>'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/engine.rb:571:in `block in <class:Engine>'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/deployer/rl4/releases/20130424201053/config/environment.rb:5:in `<top (required)>'
config.ru:4:in `require'
config.ru:4:in `block in <main>'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
config.ru:1:in `new'
config.ru:1:in `<main>'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn.rb:44:in `eval'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn.rb:44:in `block in builder'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:722:in `call'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:722:in `build_app!'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:595:in `init_worker_process'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:615:in `worker_loop'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:511:in `maintain_worker_count'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:277:in `join'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/bin/unicorn:126:in `<top (required)>'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/bin/unicorn:19:in `load'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/bin/unicorn:19:in `<main>'
这里是你如何解决它。
Considring你已经有SMTP设置在您的开发和production.rb
的Gemfile
gem 'exception_notification' ,'3.0.0', :require => 'exception_notifier'
application.rb中
config.middleware.use ExceptionNotifier,
:email_prefix => "[ERROR]",
:sender_address => %{"Exception Notifier" <[email protected]>},
:exception_recipients => %w{[email protected]}
application_controller.rb
#render 500 error
def render_error(exception)
ExceptionNotifier::Notifier.exception_notification(request.env, exception).deliver
respond_to do |f|
...
end
end
对我来说,它既适用于开发和生产(Heroku)。
希望它能帮助你。
欢呼声:)
它让我感到羞愧,说我对这个问题的解决方法是如此微不足道。在我的部署过程
$ cap unicorn:stop
$ cap unicorn:start
我重新开始的任务是从来没有真正停止服务器的实例,因此没有被加载的新库,因此例外。
女士们,先生们,别忘了关掉它,然后再打开。永远。感谢所有帮助我解决这个问题的人。
但为什么你同时使用'exception_notification'和'exception_notifier'?我认为只需使用'exception_notification'即可。除了'exception_notifier'对'exception_notification'不是必需的。最后一件事'exception_notifier'和'exception_notification_rails'已经过了近3年的时间。你绝对应该只使用'exception_notification'。 – 2013-04-24 14:01:26
感谢您的评论,但拿出要求并没有解决它。该库仍未被其他服务器上的应用程序在生产中确认。 – 2013-04-24 20:18:10
你正在使用什么'exception_notification'版本?什么是完整的堆栈跟踪错误?您是否尝试过使用'ExceptionNotifier.notify_exception'而不是'ExceptionNotifier :: Notifier.exception_notification'? https://github.com/smartinez87/exception_notification#background-notifications – 2013-04-24 20:48:50