浏览 2153 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-11-04
最后修改:2010-01-13
gem 方式1: sudo gem sources -a http://gemcutter.org gem install super_exception_notifier gem 方式2: mkdir -p ~/src cd ~/src git clone git://github.com/pboling/exception_notification.git cd exception_notification gem build exception_notification.gemspec sudo gem install super_exception_notification-2.0.0.gem # (Or whatever version gets built) plugin git 方式: ./script/plugin install git://github.com/pboling/exception_notification.git plugin svn 方式: ./script/plugin install http://super-exception-notifier.googlecode.com/svn/trunk/super_exception_notifier application controller 中加入 class ApplicationController < ActionController::Base include ExceptionNotifiable ... end 配置exception_notifier 添加文件 exception_notifier.rb 到 config/initializers/exception_notifier.rb exception_notifier.rb : ExceptionNotifier.configure_exception_notifier do |config| # If left empty web hooks will not be engaged config[:web_hooks] = [] config[:app_name] = "[Project Name]" # NOTE: THERE IS A BUG IN RAILS 2.3.3 which forces us to NOT use anything but a simple email address string for the sender address. # https://rails.lighthouseapp.com/projects/8994/tickets/2340 # config[:sender_address] = %("#{(defined?(Rails) ? Rails.env : RAILS_ENV).capitalize} Error" <super.exception.notifier@example.com>) config[:sender_address] = %("Project Name" <project_name.error@mail.project_name.com>) config[:exception_recipients] = %w(project_name@googlegroups.com) # Customize the subject line #config[:subject_prepend] = "[#{(defined?(Rails) ? Rails.env : RAILS_ENV).capitalize} ERROR] " config[:subject_prepend] = "[ProjectName ERROR] " config[:subject_append] = " :(" # Include which sections of the exception email? config[:sections] = %w(request session environment backtrace) # Only use this gem to render, never email #defaults to false - meaning by default it sends email. Setting true will cause it to only render the error pages, and NOT email. config[:skip_local_notification] = true # Example: #config[:view_path] = 'app/views/error' config[:view_path] = nil # Error Notification will be sent if the HTTP response code for the error matches one of the following error codes config[:notify_error_codes] = %W( 405 500 503 ) # Error Notification will be sent if the error class matches one of the following error error classes config[:notify_error_classes] = %W( ) # What should we do for errors not listed? config[:notify_other_errors] = true # If you set this SEN will config[:git_repo_path] = nil config[:template_root] = "#{File.dirname(__FILE__)}/../views" end 配置ActionMailer 可以加一个配置文件 config/config.yml public: smtp_server: 'mail.xxxx.com' smtp_port: 25 smtp_domain: 'www.xxxx.com' smtp_user_name: 'info@xxxx.com' smtp_passwd: "" smtp_authentication: 'login' test: smtp_server: 'mail.xxxx.com' smtp_port: 25 smtp_domain: 'www.xxxx.com' smtp_user_name: 'info@xxxx.com' smtp_passwd: "" smtp_authentication: 'login' development: smtp_server: 'mail.xxxx.com' smtp_port: 25 smtp_domain: 'mail.xxxx.com' smtp_user_name: 'info@xxxx.com' smtp_passwd: "" smtp_authentication: 'login' production: smtp_server: 'mail.xxxx.com' smtp_port: 25 smtp_domain: 'mail.xxxx.com' smtp_user_name: '' smtp_passwd: '' smtp_authentication: '' 加文件 20_mailer_config.rb PUBLIC_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")['public'] PRIVATE_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")[RAILS_ENV] CONFIG = PUBLIC_CONFIG.merge(PRIVATE_CONFIG || Hash.new) ActionMailer::Base.smtp_settings = { :address => CONFIG['smtp_server'], :port => CONFIG['smtp_port'], :domain => CONFIG['smtp_domain'], :user_name => (CONFIG['smtp_authentication'].blank? ? nil : CONFIG['smtp_user_name']), :password => (CONFIG['smtp_authentication'].blank? ? nil : CONFIG['smtp_passwd']), :authentication => (CONFIG['smtp_authentication'].blank? ? nil : CONFIG['smtp_authentication']) } ActionMailer::Base.perform_deliveries = true ActionMailer::Base.raise_delivery_errors = true 如果gem方式要加入gem 引用到 config/environment.rb config.gem 'super_exception_notifier', :version => '~> 2.0.0', :lib => "exception_notifier" 如果要在本地测试要作下面三件事情: 1.服务要以production模式启动 2.config/initializers/exception_notifier.rb 中 config[:skip_local_notification] = false 3.在application controller 加 local_addresses.clear 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |