问题
I have this code in 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'
...
Right now my module looks like:
# lib/exception_mailer.rb
require 'action_mailer'
require 'active_support'
module ExceptionMailer
# Method to capture and handle all exceptions
rescue_from Exception do |ex|
...
And I am getting: undefined method 'rescue_from' for ExceptionMailer:Module
I've googled 'how do i include rescue_from in a module?' -- and I'm still a little lost.
回答1:
module Exceptionailer
# http://api.rubyonrails.org/classes/ActiveSupport/Concern.html
extend ActiveSupport::Concern
included do
rescue_from Exception do |ex|
...
end
end
end
来源:https://stackoverflow.com/questions/26048483/how-do-i-require-activesupports-rescue-from-method