Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: How do I require ActiveSupport's rescue_from method?

I have this code in application controller:

# Method to capture and handle all exceptions
rescue_from Exception do |ex|
  Rails.logger.debug ex
  do_stuff(ex)
end

I want to move this into a module and then:

class ApplicationController < ActionController::Base
  include 'module'
...

Right now my module looks like:

# lib/exception_mailer.rb
require 'action_mailer'
require 'active_support'

module ExceptionMailer

  # Method to capture and handle all exceptions
  rescue_from Exception do |ex|
...

And I am getting: undefined method 'rescue_from' for ExceptionMailer:Module

I've googled 'how do i include rescue_from in a module?' -- and I'm still a little lost.

like image 914
Eric Francis Avatar asked Sep 25 '14 21:09

Eric Francis


1 Answers

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

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

end
like image 186
Eric Francis Avatar answered Nov 13 '22 12:11

Eric Francis