exception_notification使用手记

[b]笔者在学习使用exception_notification时,碰了不少壁,希望大家可以避免,呵呵。[/b]

1. exception_notification 采用rails中的actionMailer发送邮件,所以使用这个的一个前提是确保actionmailer可以正常发送。
config/environment.rb:
[code]Rails::Initializer.run do |config|
...
config.action_mailer.raise_delivery_errors = true
# set delivery method to :smtp, :sendmail or :test
config.action_mailer.delivery_method = :smtp
# these options are only needed if you choose smtp delivery
config.action_mailer.smtp_settings = {
:address => 'mail.ux168.cn',
:port => 25,
:domain => 'ux168.cn',
:authentication => :login,
:user_name => 'hello@ux168.cn',
:password => '123456'
}
end[/code]


2. install and config exception_notification :
railsroot# ruby script/plugin install exception_notification
在相应的控制中增加代码:
[code] class ApplicationController < ActionController::Base
include ExceptionNotifiable
... # other code
end[/code]
environment.rb中增加指定的接收人:
[code] Rails::Initializer.run do |config|
... # config
end
ExceptionNotifier.exception_recipients = ['oushunbao@ux168.cn'][/code]

3. test
测试时要注意,
1.不能在本机测试,最好换一台。当然,你只要不使用127.0.0.1 ,基本上也可以骗过系统,进行测试。
2.必须使用production环境,否则无效。
3.发送的消息只限于500错误的消息。
如果需要更改这个规则,清更改相应的代码:
railsroot/vendor/plugins/exception_notification/lib/exception_notifiable.rb中的:
[code] def rescue_action_in_public(exception)
...
end[/code]

还有什么问题,可以看看这个文档:
[b] http://svn.rubyonrails.org/rails/plugins/exception_notification/README[/b]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值