加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 我如何需要ActiveSupport的rescue_from方法?

发布时间:2020-12-17 04:17:18 所属栏目:百科 来源:网络整理
导读:我在应用程序控制器中有这个代码: # Method to capture and handle all exceptionsrescue_from Exception do |ex| Rails.logger.debug ex do_stuff(ex)end 我想把它移到一个模块然后: class ApplicationController ActionController::Base include 'module
我在应用程序控制器中有这个代码:
# 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|
...

我得到:ExceptionMailer:Module的未定义方法’rescue_from’

我用Google搜索了“我如何在模块中包含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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读