Eri*_*cis 10 module ruby-on-rails activesupport
我有这个代码application controller:
# Method to capture and handle all exceptions
rescue_from Exception do |ex|
Rails.logger.debug ex
do_stuff(ex)
end
Run Code Online (Sandbox Code Playgroud)
我想把它移到一个模块然后:
class ApplicationController < ActionController::Base
include 'module'
...
Run Code Online (Sandbox Code Playgroud)
现在我的模块看起来像:
# lib/exception_mailer.rb
require 'action_mailer'
require 'active_support'
module ExceptionMailer
# Method to capture and handle all exceptions
rescue_from Exception do |ex|
...
Run Code Online (Sandbox Code Playgroud)
我得到了: undefined method 'rescue_from' for ExceptionMailer:Module
我用Google搜索了"我如何在模块中包含rescue_from?" - 我还有点失落.
Eri*_*cis 17
module Exceptionailer
# http://api.rubyonrails.org/classes/ActiveSupport/Concern.html
extend ActiveSupport::Concern
included do
rescue_from Exception do |ex|
...
end
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4076 次 |
| 最近记录: |