2014-09-25 24 views
7

Ben application controller bu kodu vardır:ActiveSupport'un rescue_from yöntemini nasıl gerektirebilirim?

# Method to capture and handle all exceptions 
rescue_from Exception do |ex| 
    Rails.logger.debug ex 
    do_stuff(ex) 
end 

Sonra bir modül ve içine bu hareket etmek istiyorum:

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

module ExceptionMailer 

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

Ve I:

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

Şu anda benim modül benziyor alıyorum: undefined method 'rescue_from' for ExceptionMailer:Module

Ben googled ettik 'Rescue_from'u bir modülde nasıl eklerim?' - ve hala biraz kayboldum.

+0

Bu bağlantı size yardımcı olabilir. http://apidock.com/rails/ActiveSupport/Rescuable/ClassMethods/rescue_from – Joel

+0

Sanırım ActiveSupport :: Concern'i genişletmek ve 'do do 'blokunu kullanarak bir çözüm buldum. Raylar benim gemimin bir bağımlılığıdır. Şu anda herhangi bir şeye ihtiyacım yok. –

cevap

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

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

end