`
hellosoft
  • 浏览: 54829 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

exception_notification使用手记

阅读更多
笔者在学习使用exception_notification时,碰了不少壁,希望大家可以避免,呵呵。

1. exception_notification 采用rails中的actionMailer发送邮件,所以使用这个的一个前提是确保actionmailer可以正常发送。
config/environment.rb:
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



2. install and config exception_notification :
   railsroot# ruby script/plugin install exception_notification
   在相应的控制中增加代码:
     class ApplicationController < ActionController::Base
       include ExceptionNotifiable
       ... # other code
     end

environment.rb中增加指定的接收人:
     Rails::Initializer.run do |config|
    ... # config
    end
     ExceptionNotifier.exception_recipients = ['oushunbao@ux168.cn']

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

    
还有什么问题,可以看看这个文档:
http://svn.rubyonrails.org/rails/plugins/exception_notification/README
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics