gpt4 book ai didi

ruby-on-rails - ExceptionNotifier 常量未初始化的 Rails 3

转载 作者:太空狗 更新时间:2023-10-29 11:15:12 26 4
gpt4 key购买 nike

我已经阅读了该站点上的许多问题以及有关 ExceptionNotifier 及其在 Rails 3 中的实现的 GitHub 文档,但我不明白为什么它在我的生产服务器上对我不起作用。在我的本地机器(Mac)上,它在生产环境中完美运行。但是在我使用 capistrano 部署并在 Linux 机器上使用 unicorn 运行应用程序之后,我的 unicorn 日志提示我的 environments/production.rb 文件中有一个 uninitialized constant ExceptionNotifier,即使我的本地机器似乎认为没关系。我已经尝试过这两种实现:gem 'exception_notification', :require => 'exception_notifier'gem 'exception_notification_rails3', :require => 'exception_notifier'。两者都抛出此错误。这是我的作品.rb

Rl4::Application.configure do
# code omitted
# Enable ExceptionNotifier, having it ignore its default exceptions
config.middleware.use ExceptionNotifier,
sender_address: 'reports@ctatechs.com',
exception_recipients: 'brice@ctatechs.com',
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,它实现了 gem:

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 机器上为 gem 的两个版本以及“exception_notifier”运行了 sudo gem install。没有骰子。想法?

附加信息我只是尝试将 gem 作为插件重新安装,但在将 production.rb 文件更改为使用 config.middleware.use::ExceptionNotifier 后出现了同样的错误。但是,这些修改在我的本地机器上仍然有效。也许我在 Linux 机器上遗漏了另一个软件?文档中似乎没有提及任何内容......

请求gem版本

我正在使用 exception_notification,v. 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>'

最佳答案

这是您可以解决的方法。

考虑到您已经在开发和生产中设置了 SMTP.rb

gem 文件

gem 'exception_notification' ,'3.0.0', :require => 'exception_notifier'

application.rb

config.middleware.use ExceptionNotifier,
:email_prefix => "[ERROR]",
:sender_address => %{"Exception Notifier" <XYZ@gmail.com>},
:exception_recipients => %w{ABC@gmail.com}

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

希望对你也有帮助。
干杯:)

关于ruby-on-rails - ExceptionNotifier 常量未初始化的 Rails 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16180494/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com