0

I use Exception Notifier for handling errors in my app and in /config/initializers/exception_notification.rb I have followings:

MyAPP::Application.config.middleware.use ExceptionNotifier,
  :email_prefix => "[ERROR] ",
  :sender_address => '"Notifier" <notifier@yourdomain.com>',
  :exception_recipients => ['account@gmail.com']

But the notification email is sent also in development mode, how can I allow sending email only in production mode?

4

1 回答 1

4

You can configure the ExceptionNotifier separately for each environment. See also the documentation.

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.

So you just configure it in your config/environments/production.rb with e.g.

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

There is also a nice blog entry handling this topic.

于 2012-04-30T09:57:14.593 回答