exception_notification使用手記
筆者はexceptionの使い方を勉強しています.notificationの时、多くの壁にぶつかって、みんなが避けることができることを望んで、ほほほ.
1. exception_notificationはrailsのactionMailerを使用してメールを送信するので、これを使用する前提はactionmailerが正常に送信できることを確保することです.
config/environment.rb:
2. install and config exception_notification :
railsroot# ruby script/plugin install exception_notification
対応する制御にコードを追加します.
Environment.rbで指定した受信者を追加します.
3. test
テスト時に注意してください.
1.本機でテストできないので、交換したほうがいいです.もちろん、127.0.0.1を使用しない限り、基本的にシステムをだましてテストすることもできます.
2.production環境を使用する必要があります.そうしないと無効です.
3.送信されたメッセージは500エラーのメッセージのみです.
このルールを変更する必要がある場合は、対応するコードをクリアします.
railsroot/vendor/plugins/exception_notification/lib/exception_notifiable.rb:
このドキュメントを参照してください.
http://svn.rubyonrails.org/rails/plugins/exception_notification/README
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 => '[email protected]',
: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 = ['[email protected]']
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