ruby-on-rails – ExceptionNotifier和rescue_from

我试图实现exception_notifier和一个自定义的异常处理
在我的rails 3应用程序当我只使用异常通知器一切正常.
在开发模式中
config.consider_all_requests_local = false

一个rescue_from在我的application_controller中:

unless Rails.application.config.consider_all_requests_local
  rescue_from Exception,:with => :render_error
end

def render_error(exception)
  ExceptionNotifier::Notifier.exception_notification(request.env,exception).deliver
end

在我的application.rb

config.middleware.use ExceptionNotifier,:email_prefix => "Error: ",:sender_address => %{"notifier" <notifier@wannagohome.com>},:exception_recipients => %w{ myself@fail.com }

唯一的问题似乎是,这些选项没有加载到request.env中.
我在一个额外的初始化程序中尝试过该文件,我不知道还有什么 – 它不工作.
目前我有一个非常难看的黑客,在那里我把request.env和
发送电子邮件之前哈希
任何想法?

解决方法

exception_notification是Rails 3中的中间件,所以这些选项直接设置在处理调用的类中,该类不会在环境中设置它们,除非它捕获异常( see here). This fork添加一个可以使用的background_exception_notification方法.我借了这个想法,刚刚添加了这个帮助方法
def background_exception_notification(env,exception)
  if notifier = Rails.application.config.middleware.detect { |x| x.klass == ExceptionNotifier }
    env['exception_notifier.options'] = notifier.args.first || {}                   
    ExceptionNotifier::Notifier.exception_notification(env,exception).deliver
    env['exception_notifier.delivered'] = true
  end
end

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...