2

我已閱讀了本網站上的許多問題以及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>' 
+0

但爲什麼你同時使用'exception_notification'和'exception_notifier'?我認爲只需使用'exception_notification'即可。除了'exception_notifier'對'exception_notification'不是必需的。最後一件事'exception_notifier'和'exception_notification_rails'已經過了近3年的時間。你絕對應該只使用'exception_notification'。 – 2013-04-24 14:01:26

+0

感謝您的評論,但拿出要求並沒有解決它。該庫仍未被其他服務器上的應用程序在生產中確認。 – 2013-04-24 20:18:10

+0

你正在使用什麼'exception_notification'版本?什麼是完整的堆棧跟蹤錯誤?您是否嘗試過使用'ExceptionNotifier.notify_exception'而不是'ExceptionNotifier :: Notifier.exception_notification'? https://github.com/smartinez87/exception_notification#background-notifications – 2013-04-24 20:48:50

回答

0

這裏是你如何解決它。

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)。

希望它能幫助你。
歡呼聲:)

1

它讓我感到羞愧,說我對這個問題的解決方法是如此微不足道。在我的部署過程

$ cap unicorn:stop 
$ cap unicorn:start 

我重新開始的任務是從來沒有真正停止服務器的實例,因此沒有被加載的新庫,因此例外。

女士們,先生們,別忘了關掉它,然後再打開。永遠。感謝所有幫助我解決這個問題的人。

相關問題