Rails: Как мне использовать метод Rescue_from ActiveSupport?

У меня есть этот код в application controller:

# 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|
...

И я получаю: undefined method 'rescue_from' for ExceptionMailer:Module

Я погуглил: «Как мне включить Rescue_from в модуль?» -- И я все еще немного потерян.


person Eric Francis    schedule 25.09.2014    source источник
comment
Эта ссылка может вам помочь. apidock.com/rails/ActiveSupport/Rescuable/ClassMethods/   -  person Joel    schedule 26.09.2014
comment
Я думаю, что нашел решение, выполняющее extend ActiveSupport::Concern и использующее блок included do. Rails является зависимостью моего драгоценного камня. В настоящее время мне не нужно ничего требовать.   -  person Eric Francis    schedule 26.09.2014


Ответы (1)


person    schedule
comment
Добавление extend ActiveSupport::Concern и использование блока included do устранили проблему для меня. - person Promise Preston; 16.12.2020