Exception Notification Gem and Rails 3

匿名 (未验证) 提交于 2019-12-03 02:44:02

问题:

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

http://github.com/rails/exception_notification

In my Gemfile I have

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.

回答1:

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

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

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

config.middleware.use ExceptionNotifier,   :email_prefix => "[Exception] ",   :sender_address => %{"Exception Notifier" <support@example.com>},   :exception_recipients => %w{you@me.com} 


回答2:

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

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



回答3:

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{office@application.com},   :exception_recipients => %w{office@application.com} 


回答4:

Keep it simple silly

In gemfile

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

In application.rb file

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

Your are Done.. :*



回答5:

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:

config.middleware.use "::ExceptionNotifier"

instead of

config.middleware.use ExceptionNotifier



回答6:

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

In the Gemfile

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

In config\initializers\exception_notification.rb

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


回答7:

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

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

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



回答8:

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

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


回答9:

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.

Gemfile:

gem 'exception_notification' 

Initializer:

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


回答10:

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

    config.middleware.use ExceptionNotifier,   :email_prefix => "[some prefix] ",   :sender_address => %{"Notifier" <notify@domain.com>},   :exception_recipients => %w{recipient@domain.com} 

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.



回答11:

I had the same problem just now and resolved it this way:

Gemfile

source 'http://rubygems.org' gem 'exception_notification_rails3', :require => 'exception_notifier' 

application.rb

config.middleware.use ExceptionNotifier,   :email_prefix => "[some prefix] ",   :sender_address => %{"Notifier" <notify@domain.com>},   :exception_recipients => %w{recipient@domain.com} 

I'm refactoring a Rails 2.3 project to 3.0, so I haven't tried this on a fresh install.

Edit:

It might actually be better (or "more correct") to put the ExceptionNotifier initialization in a separate initializer file in config/initializers/ instead of application.rb.

config/initializers/exception_notifier.rb

MyApp::Application.config.middleware.use ExceptionNotifier,   :email_prefix => "[some prefix] ",   :sender_address => %{"Notifier" <notify@domain.com>},   :exception_recipients => %w{recipient@domain.com} 


回答12:

Using Rails 3.0.3 this works for me:

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

:git part is imported because its a patched version to get around the 'undefined method controller_name error' and :require to require the right lib.

Then in my production.rb environment file i only have this (from the manual)

  config.middleware.use ExceptionNotifier,     :email_prefix => "[MyApp] ",     :sender_address => %{"notifier" <email@example.com>},     :exception_recipients => %w{email@example.com} 

Seems like there are many different ways to get this to work, but this was my way.

Cheers!



回答13:

It took a bit of work but I got Exception Notifier working with Rails 3.0.0:

1- rails plugin install http://github.com/sickill/exception_notification.git

(If you don't want to use this fork, just apply his patch manually to the original Rails plugin: it is only 3 lines.) It fixes the 'undefined method controller_name error'

2- In application.rb:

config.middleware.use "::ExceptionNotifier" , :email_prefix => "[Whatever] ",                            :sender_address => %{"notifier" <notifier@example.com>},                            :exception_recipients => %w{whoever@example.com}  

3- Apply Lawrence Pit's patch. (UPDATE: This link appears to be broken) It fixes the uninitialized constant ActiveRecord::RecordNotFound error as documented here.

That's it.



回答14:

till now ( 2012-Aug-03) the official site is : https://github.com/smartinez87/exception_notification, and according the README, it support Rails3 perfectly.

step1. edit your Gemfile:

gem 'exception_notification' 

step2.

As of Rails 3 ExceptionNotification is used as a rack middleware, so you can configure its options on your config.ru file, or in the environment you want it to run. In most cases you would want ExceptionNotification to run on production. You can make it work by

Whatever::Application.config.middleware.use ExceptionNotifier,   :email_prefix => "[Whatever] ",   :sender_address => %{"notifier" <notifier@example.com>},   :exception_recipients => %w{exceptions@example.com} 


回答15:

I am using rails 3.0.4 and had the same issue as above. The only solution that worked for me was to install the v1.2 of the exception_notification for rails 3 (make sure you use the correct branch/version) as a PLUGIN

rails plugin install https://github.com/railsware/exception_notification.git 

and use in production.rb the code everyone mentions:

config.middleware.use ExceptionNotifier,   :email_prefix => "[some prefix] ",   :sender_address => %{"Notifier" <notify@domain.com>},   :exception_recipients => %w{recipient@domain.com} 

It definitely did not work for me as a gem and the readme does say " Exception Notifier Plugin for Rails " and mentions nothing about installing it as gem.

Harry



回答16:

UPDATED ANSWER as of 3/14...

You just need to do gem exception_notification in your gem file. No 'require' needed.

Also, other changes just straight from the docs...

"As of 4.x version the configuration syntax has changed. All email related options MUST BE nested under the :email key."

like so...

Whatever::Application.config.middleware.use ExceptionNotification::Rack,   :email => {     :email_prefix => "[Whatever] ",     :sender_address => %{"notifier" <notifier@example.com>},     :exception_recipients => %w{exceptions@example.com}   } 


回答17:

I copied and pasted the exception_notification config from old app to new one and it failed. It brought me here and none of the above answers were up-to-date. Since 4.x version the middleware was renamed to ExceptionNotification::Rack, so middleware config looks like that:

Whatever::Application.config.middleware.use ExceptionNotification::Rack,  :email => {    :email_prefix => "[Whatever] ",    :sender_address => %{"notifier" <notifier@example.com>},    :exception_recipients => %w{exceptions@example.com}  } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!