7
我有這樣的代碼在application controller
:如何要求ActiveSupport的rescue_from方法?
# 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
我google了'我如何在模塊中包含rescue_from?' - 我還是有點迷路。
此鏈接可能會幫助你。 http://apidock.com/rails/ActiveSupport/Rescuable/ClassMethods/rescue_from – Joel 2014-09-25 21:48:29
我想我找到了一個解決方案來做'擴展ActiveSupport :: Concern'並使用'included do'塊。 Rails是我的寶石的依賴。我目前不需要任何東西。 – 2014-09-25 22:53:05