Ruby-on-rails 异常通知 Gem 和 Rails 3

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3524127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:04:50  来源:igfitidea点击:

Exception Notification Gem and Rails 3

ruby-on-railsexception-handlingruby-on-rails-3ruby-on-rails-plugins

提问by Darren Hinderer

I'm trying to get this up and running, but I see "uninitialized constant ExceptionNotifier" whenever I start my server.

我正在尝试启动并运行它,但是每当我启动服务器时,我都会看到“未初始化的常量 ExceptionNotifier”。

http://github.com/rails/exception_notification

http://github.com/rails/exception_notification

In my Gemfile I have

在我的 Gemfile 中,我有

gem "exception_notification", :git => "http://github.com/rails/exception_notification.git", :branch => "master"

gem "exception_notification", :git => " http://github.com/rails/exception_notification.git", :branch => "master"

I've tried putting the configuration as shown in the github readme inside of config/application.rb, config/environment.rb, and config.ru. I replaced "Whatever" with my application name.

我尝试将 github 自述文件中所示的配置放在 config/application.rb、config/environment.rb 和 config.ru 中。我用我的应用程序名称替换了“随便”。

回答by Jan M

All previous answers are outdated, you can now simply add this to your gemfile:

以前的所有答案都已过时,您现在只需将其添加到您的 gemfile 中即可:

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

And edit your production.rb config file as indicated in the readme:

并按照自述文件中的说明编辑您的 production.rb 配置文件:

config.middleware.use ExceptionNotifier,
  :email_prefix => "[Exception] ",
  :sender_address => %{"Exception Notifier" <[email protected]>},
  :exception_recipients => %w{[email protected]}

回答by Sebastian Martinez

Latest version of official gem works with Rails 3, you can find it here: https://github.com/smartinez87/exception_notification.

官方 gem 的最新版本适用于 Rails 3,您可以在这里找到它:https: //github.com/smartinez87/exception_notification

Next gem release will make the :require => 'exception_notifier'option unnecessary.

下一个 gem 版本将使该:require => 'exception_notifier'选项变得不必要。

回答by BvuRVKyUVlViVIc7

Ok, its working now for me:

好的,它现在对我有用:

# Gemfile
gem "exception_notification", :git => "git://github.com/rails/exception_notification", :require => 'exception_notifier'

# application.rb, inside the config block
config.middleware.use ::ExceptionNotifier,
  :email_prefix => "ApplicationName-Errors: ",
  :sender_address => %w{[email protected]},
  :exception_recipients => %w{[email protected]}

回答by Saqib R.

Keep it simple silly

In gemfile

保持简单愚蠢

gemfile 中

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

In application.rb file

application.rb 文件中

  config.middleware.use ExceptionNotifier,
 :email_prefix => "[ERROR] ",
 :sender_address => %{"Exception Notifier" <[email protected]>},
 :exception_recipients => %w{[email protected]}

Your are Done.. :*

你完成了.. :*

回答by dave elkins

The official repo on github is now: https://github.com/smartinez87/exception_notification

github上的官方repo现在是:https: //github.com/smartinez87/exception_notification

In the Gemfile

在 Gemfile 中

gem "exception_notification", :require => 'exception_notifier', :git => "https://github.com/smartinez87/exception_notification.git"

In config\initializers\exception_notification.rb

在 config\initializers\exception_notification.rb

Rails.application.config.middleware.use ExceptionNotifier,
  :email_prefix => "[Whatever] ",
  :sender_address => %{"notifier" <[email protected]>},
  :exception_recipients => %w{[email protected]}  

回答by Darren Hinderer

It seems that Rails 3 can't use this plugin in gem form. Maybe rack apps can't be loaded from gems? I installed it as a plugin instead and changed the config syntax to:

Rails 3 好像不能以 gem 的形式使用这个插件。也许机架应用程序无法从 gems 加载?我将其安装为插件,并将配置语法更改为:

config.middleware.use "::ExceptionNotifier"

config.middleware.use "::ExceptionNotifier"

instead of

代替

config.middleware.use ExceptionNotifier

config.middleware.use ExceptionNotifier

回答by Chris Shepherd

I was able to get it to work with the following in production.rb:

我能够让它在 production.rb 中使用以下内容:

config.after_initialize do
 config.middleware.use ExceptionNotifier,
      :email_prefix => "[Whatever] ",
      :sender_address => %{"notifier" <[email protected]>},
      :exception_recipients => %w{[email protected]}
end

回答by nathanvda

Actually, now, it is much easier. In your Gemfileyou need to write:

实际上,现在要容易得多。在Gemfile你需要写:

gem "exception_notification", :git => "http://github.com/rails/exception_notification.git", :require => 'exception_notifier'

And all should be fixed. The :requireoption is crucial (i guess because the names differ you have to specify explicitly). All other patches mentioned before have been merged i presume.

一切都应该是固定的。该:require选项至关重要(我猜是因为名称不同,您必须明确指定)。我认为之前提到的所有其他补丁都已合并。

回答by Brian Samson

https://github.com/smartinez87/exception_notification

https://github.com/smartinez87/exception_notification

This gem has been updated for rails 3.x and I just tested on 3.0.7 and the installation is much simpler.

这个 gem 已经针对 rails 3.x 进行了更新,我刚刚在 3.0.7 上进行了测试,安装要简单得多。

Gemfile:

宝石档案:

gem 'exception_notification'

Initializer:

初始化程序:

Rails.application.config.middleware.use ExceptionNotifier,
  :email_prefix => "[Whatever] ",
  :sender_address => %{"notifier" <[email protected]>},
  :exception_recipients => %w{[email protected]}

回答by Stone

If you are doing a rescue_from Exception, with: :render_500to handle showing a 500 template/page it no longer sends an email with just this

如果您正在rescue_from Exception, with: :render_500处理显示 500 个模板/页面,它不再发送仅包含此内容的电子邮件

    config.middleware.use ExceptionNotifier,
  :email_prefix => "[some prefix] ",
  :sender_address => %{"Notifier" <[email protected]>},
  :exception_recipients => %w{[email protected]}

You'll need to manually send it in the method that handles the exception

您需要在处理异常的方法中手动发送它

def render_500(exception)
    # email an error email if there's a 500 in production mode
    if Rails.env.production?
        ExceptionNotifier::Notifier.exception_notification(request.env, exception).deliver
    end
end 

So put the config stuff in your environment (production.rb) and the Exception handling code in your application controller.

因此,将配置内容放在您的环境 (production.rb) 中,并将异常处理代码放在您的应用程序控制器中。