2014-09-25 13 views
7

Mam ten kod w application controller:Jak wymagać metody rescue_from ActiveSupport?

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

Chcę przenieść to do modułu, a następnie:

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

Teraz mój moduł wygląda następująco:

# 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 Otrzymuję: undefined method 'rescue_from' for ExceptionMailer:Module

Mam google "jak dołączyć plik rescue_from do modułu?" - i wciąż jestem trochę zagubiony.

+0

Ten link może ci pomóc. http://apidock.com/rails/ActiveSupport/Rescuable/ClassMethods/rescue_from – Joel

+0

Myślę, że znalazłem rozwiązanie polegające na 'rozszerzeniu ActiveSupport :: Concern' i użyciu' włączonego bloku ''. Rails to zależność mojego klejnotu. W tej chwili nie potrzebuję niczego wymagać. –

Odpowiedz

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

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

end 
Powiązane problemy