用ExceptionNotifier插件打造無人值守的管理員

當你的網站出現問題時,讓它發送一份錯誤報告到你的郵箱不是一件挺好的事嗎?這樣你就不必再被客戶抱怨不能及時發現問題了。

 

環境:

Rails 2.3.3

Ruby 1.8.6

 

1.安裝

 

ruby script/plugin install exception_notification

 

2. 配置

 

   a.environment.rb 文件

 

Rails::Initializer.run do |config|

        config.action_mailer.smtp_settings = {
            :address =>        "mail.taito.com",
            :port =>           25,
            :domain =>         "mail.taito.com",
            :authentication => :login,
            :user_name =>      "[email protected]",
           :password =>       "******"
      }
   ...
   ...
end
ExceptionNotifier.sender_address = %w([email protected])
ExceptionNotifier.exception_recipients = %w([email protected])

 

   注意上面的配置順序不要搞錯了

 

b.application_controller.rb

 

class ApplicationController < ActionController::Base

  include ExceptionNotifiable

  ......

end

 

c. 如果你是在development.rb模式做測試

 

   development.rb 文件中要修改

 

 

config.action_mailer.raise_delivery_errors = false  
config.action_controller.consider_all_requests_local = true 

 爲:

 

 

config.action_mailer.raise_delivery_errors = true  
config.action_controller.consider_all_requests_local = false 

 

並:application_controller.rb 文件中加入

 

local_addresses.clear

 

 

ok, 去測試吧......

 

 

更多配置參考plugins 中的readme文檔。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章