用Rails 2.3打造简单记账软件(11)

January 5th, 2010 (592 views)

当网站出现问题时,让它发送一份错误报告到你的邮箱是件挺不错的事,这样你就不必再担心不能及时发现问题了。

exception_notification插件的功能就是当你的Rails应用出错时,它会向指定的邮箱地址发送错误日志。

使用很简单,安装插件后配置一下邮件接受者就可以了。

安装插件

script/plugin install git://github.com/rails/exception_notification.git

在config/environment.rb中增加邮件接收者的地址

Rails::Initializer.run do |config|
  ...
end

ExceptionNotifier.exception_recipients = %w(youremail@domain.com)

然后告诉Exception Notifier哪些controller出错才发送日志,当然是全部啦:

class ApplicationController < ActionController::Base
  include ExceptionNotifiable
  ...
end

Exception Notifier采用Rails中的ActionMailer发送邮件,所以使用的前提是确保ActionMailer可以正常发送邮件。还有就是Exception Notifier默认只在production环境下才会生效,如果想要在development下也生效,需要将development.rb文件中的

config.action_mailer.raise_delivery_errors = false

修改为

config.action_mailer.raise_delivery_errors = true

Related Posts

Leave a Reply

Security Code: