41

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.

BvuRVKyUVlViVIc7
  • 11,641
  • 9
  • 59
  • 111
Darren Hinderer
  • 418
  • 1
  • 6
  • 12
  • See Sebastian Martinez's comment below. He maintains the official plugin, which is now at a new location (https://github.com/smartinez87/exception_notification). It works flawlessly in Rails 3. – gtd Nov 11 '11 at 15:59

17 Answers17

57

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}
BvuRVKyUVlViVIc7
  • 11,641
  • 9
  • 59
  • 111
Jan M
  • 2,205
  • 21
  • 14
21

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.

13

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}
BvuRVKyUVlViVIc7
  • 11,641
  • 9
  • 59
  • 111
10

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.. :*

Saqib R.
  • 2,919
  • 2
  • 26
  • 21
4

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

Darren Hinderer
  • 418
  • 1
  • 6
  • 12
4

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}  
dave elkins
  • 331
  • 2
  • 4
3

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.

Stone
  • 2,608
  • 26
  • 26
3

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.

nathanvda
  • 49,707
  • 13
  • 117
  • 139
  • Yes definitely. I use the above line in my Gemfile, and in my application.rb i have the `config.middleware.use ...` and that's all i needed to do. Do you still have the uninitialized constant error? – nathanvda Sep 25 '10 at 16:03
  • The `:git` part is also crucial. The latest published gem (2.3.3.0 right now) does not work with Rails 3. – Steve Madsen Oct 14 '10 at 03:09
3

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
3

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}
Brian Samson
  • 610
  • 6
  • 6
2

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}
Siwei
  • 19,858
  • 7
  • 75
  • 95
2

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.

Chris Frederick
  • 5,482
  • 3
  • 36
  • 44
Ryan Horrisberger
  • 955
  • 11
  • 16
2

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}
Fredrik Boström
  • 1,499
  • 1
  • 19
  • 22
2

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!

1

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}
  }
bwest87
  • 1,223
  • 13
  • 12
1

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

harryhorn
  • 892
  • 6
  • 8
0

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}
 }
Casual Coder
  • 1,492
  • 2
  • 14
  • 15