我如何需要ActiveSupport的rescue_from方法? [英] How do I require ActiveSupport's rescue_from method?
本文介绍了我如何需要ActiveSupport的rescue_from方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在application controller
中有此代码:
# Method to capture and handle all exceptions
rescue_from Exception do |ex|
Rails.logger.debug ex
do_stuff(ex)
end
我想将其移动到模块中,然后:
I want to move this into a module and then:
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|
...
我得到:undefined method 'rescue_from' for ExceptionMailer:Module
我已经在Google搜索我如何在模块中包含rescue_from?" -而且我还是有些迷茫.
I've googled 'how do i include rescue_from in a module?' -- and I'm still a little lost.
推荐答案
module Exceptionailer
# http://api.rubyonrails.org/classes/ActiveSupport/Concern.html
extend ActiveSupport::Concern
included do
rescue_from Exception do |ex|
...
end
end
end
这篇关于我如何需要ActiveSupport的rescue_from方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文