[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]
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]