gpt4 book ai didi

ruby-on-rails - rails : How do I require ActiveSupport's rescue_from method?

转载 作者:行者123 更新时间:2023-12-04 01:51:21 27 4
gpt4 key购买 nike

我在 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?” ——我还是有点迷茫。

最佳答案

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

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

end

关于ruby-on-rails - rails : How do I require ActiveSupport's rescue_from method?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26048483/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com