第一次配置时,网上资料较乱,走了很多弯路。特在此记录。 git
配置环境:Ruby 1.9.3 Rails 3.2.2 github
1.安装 exception_notification gem ruby
在Gemfile中添加 服务器
gem 'exception_notification', '3.0.0'注:我第一次使用的是最新版本4.0.0,遇到一个错误 undefined method `underscore' for nil:nilclass 没法解决,后来换了3.0.0 就OK了
2.在environment.rb中配置 app
这是个人environment.rb, 仅供参考 dom
其中HELLOWORLD为你本身的APP名称 测试
# Load the rails application require File.expand_path('../application', __FILE__) #这里配置 只有非开发环境才发送错误邮件 if Rails.env != "development" HELLOWORLD::Application.config.middleware.use ExceptionNotifier, :email_prefix => "这是邮件前缀", :sender_address => %{"Warn!" 发信人邮箱@qq.com}, #收件人 可配置多个 :exception_recipients => ["123456@qq.com","654321@qq.com"], :delivery_method => :smtp, #邮件服务器配置 :smtp_settings => { :address => "smtp.gmail.com", :port => "587", :domain => "gmail.com", :authentication => "plain", :user_name => "XXXXX@gmail.com", :password => "*********", :enable_starttls_auto => true } end # Initialize the rails application HELLOWORLD::Application.initialize!
3.重启一下Rails程序 若是你是开发环境下测试,注意修改上面的配置 ui
如今 若是程序出现异常 你应该会收到一封错误邮件 包含具体的报错信息 spa
其余的具体使用方法:https://github.com/smartinez87/exception_notification code