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_notificatio
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}
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.
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}
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.
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.
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.