ruby-on-rails – 我如何需要ActiveSupport的rescue_from方法?

我在应用程序控制器中有这个代码
# Method to capture and handle all exceptions
rescue_from Exception do |ex|
  Rails.logger.debug ex
  do_stuff(ex)
end

我想把它移到一个模块然后:

class ApplicationController < ActionController::Base
  include 'module'
...

现在我的模块看起来像:

# lib/exception_mailer.rb
require 'action_mailer'
require 'active_support'

module ExceptionMailer

  # Method to capture and handle all exceptions
  rescue_from Exception do |ex|
...

我得到:ExceptionMailer:Module的未定义方法’rescue_from’

我用Google搜索了“我如何在模块中包含rescue_from?” – 我还有点失落.

解决方法

module Exceptionailer
  # http://api.rubyonrails.org/classes/ActiveSupport/Concern.html
  extend ActiveSupport::Concern

  included do
    rescue_from Exception do |ex|
      ...
    end
  end

end

相关文章

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