Module: Edgar::RescueMixin

Included in:
EdgarController, EdgarPopupController
Defined in:
app/controllers/edgar/rescue_mixin.rb

Overview

rescue part for both EdgarController and EdgarPopupController

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) included(klass)



3
4
5
6
# File 'app/controllers/edgar/rescue_mixin.rb', line 3

def self.included(klass)
  klass.rescue_from ActiveRecord::RecordNotFound, with: :rescue_404
  klass.rescue_from Edgar::EdgarError,            with: :rescue_edgar_error
end

Instance Method Details

- (Object) rescue_404(ex) (private)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/edgar/rescue_mixin.rb', line 10

def rescue_404(ex)
  logger.debug do
    ["DEBUG: #{ex.class} #{ex.message}",
     "bactrace: #{ex.backtrace}"].join(',')
  end

  respond_to do |format|
    format.html {
      flash[:error] = v('not_found')
      redirect_to top_path
    }
    format.js {
      flash.now[:error] = v('not_found')
      render 'message_popup'
    }
  end
end

- (Object) rescue_edgar_error(ex) (private)



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/edgar/rescue_mixin.rb', line 28

def rescue_edgar_error(ex)
  logger.debug do
    ["DEBUG: #{ex.class} #{ex.message}",
     "bactrace: #{ex.backtrace}"].join(',')
  end

  respond_to do |format|
    format.html {
      flash[:error] = v(ex.class.to_s)
      redirect_to top_path
    }
    format.js {
      flash.now[:error] = v(ex.class.to_s)
      render 'message_popup'
    }
  end
end