Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Exception Notifier Plugin for Rails - Just a fork to implement the caching of the exception using Redis as the backend.

branch: master

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Exception Notifier Plugin for Rails Travis

The Exception Notifier plugin provides a mailer object and a default set of templates for sending email notifications when errors occur in a Rails application. The plugin is configurable, allowing programmers to specify:

  • the sender address of the email
  • the recipient addresses
  • the text used to prefix the subject line
  • the time between same exception notifications.

The timer option is the time that must pass in order to get notified again for the same exception. Say an exception of some class A gets raised from a controller B and from a specific action C. If another exception of the same kind (class, controller, action) gets raised within the timer option then no notification is send. This prevents the spammy behavior of the exception notification.

The email includes information about the current request, session, and environment, and also gives a backtrace of the exception.


You can use the latest ExceptionNotification gem with Rails 3, by adding the following line in your Gemfile

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

As of Rails 3 ExceptionNotification is used as a rack middleware, so you can configure its options on your 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" <>},
  :exception_recipients => %w{},
  :timer => 5.minutes


By default, the notification email includes four parts: request, session, environment, and backtrace (in that order). You can customize how each of those sections are rendered by placing a partial named for that part in your app/views/exception_notifier directory (e.g., _session.rhtml). Each partial has access to the following variables:

@controller     # the controller that caused the error
@request        # the current request object
@exception      # the exception that was raised
@backtrace      # a sanitized version of the exception's backtrace
@data           # a hash of optional data values that were passed to the notifier
@sections       # the array of sections to include in the email

You can reorder the sections, or exclude sections completely, by altering the ExceptionNotifier.sections variable. You can even add new sections that describe application-specific data--just add the section's name to the list (wherever you'd like), and define the corresponding partial.

#Example with two new added sections
Whatever::Application.config.middleware.use ExceptionNotifier,
   :email_prefix => "[Whatever] ",
   :sender_address => %{"notifier" <>},
   :exception_recipients => %w{},
   :sections => %w{my_section1 my_section2} + ExceptionNotifier::Notifier.default_sections

If your new section requires information that isn't available by default, make sure it is made available to the email using the exception_data macro:

class ApplicationController < ActionController::Base
  before_filter :log_additional_data
    def log_additional_data
      request.env["exception_notifier.exception_data"] = {
        :document => @document,
        :person => @person

In the above case, @document and @person would be made available to the email renderer, allowing your new section(s) to access and display them. See the existing sections defined by the plugin for examples of how to write your own.

Background Notifications

If you want to send notifications from a background process like DelayedJob, you should use the background_exception_notification method like this:

  some code...
rescue => e

Manually notify of exception

If your controller action manually handles an error, the notifier will never be run. To manually notify of an error you can do something like the following:

rescue_from Exception, :with => :server_error

def server_error(exception)
  # Whatever code that handles the exception

  ExceptionNotifier::Notifier.exception_notification(request.env, exception).deliver


After an exception notification has been delivered the rack environment variable 'exception_notifier.delivered' will be set to +true+.

Rails 2.3 stable and earlier

If you are running Rails 2.3 then see the branch for that:

If you are running pre-rack Rails then see this tag:

Support and tickets

Copyright (c) 2005 Jamis Buck, released under the MIT license

Something went wrong with that request. Please try again.