3
3
4
4
class ApplicationController < ActionController ::Base
5
5
include AuthenticatedSystem
6
-
6
+
7
7
helper :all # include all helpers, all the time
8
8
protect_from_forgery # See ActionController::RequestForgeryProtection for details
9
-
9
+
10
10
# Scrub sensitive parameters from your log
11
11
filter_parameter_logging :password
12
12
13
13
before_filter :login_required
14
14
15
- def rescue_action e
16
- # Connection to MongoDB failed.
17
- if e . class == Mongo ::ConnectionFailure
18
- render :file => "#{ RAILS_ROOT } /public/mongo_connectionfailure.html" , :status => 500
19
- return
15
+ rescue_from Exception do |e |
16
+ if consider_all_requests_local || local_request?
17
+ rescue_action_without_handler e
18
+ else
19
+ logger . error "ERROR: #{ e . to_s } "
20
+ render :file => "#{ RAILS_ROOT } /public/500.html" , :status => 500
20
21
end
22
+ end
21
23
22
- # Default 404 error.
23
- if e . class == ActionController ::RoutingError
24
- render :file => "#{ RAILS_ROOT } /public/404.html" , :status => 404
25
- return
24
+ rescue_from ActionView ::TemplateError do |e |
25
+ # This rescue_from handling all kind of errors which is raised during template rendering.
26
+ # So, if environment is development, we should handle it as usual.
27
+ # If environment is test or production, we should handle it in particular way –
28
+ # just reraise the exception so that other rescue_from can handle it.
29
+ if Rails . env . development?
30
+ rescue_action_without_handler e
31
+ else
32
+ rescue_with_handler e . original_exception
26
33
end
34
+ end
35
+
36
+ rescue_from Mongo ::ConnectionFailure do |e |
37
+ render :file => "#{ RAILS_ROOT } /public/mongo_connectionfailure.html" , :status => 500
38
+ end
27
39
28
- # Default 500 error.
29
- logger . error "ERROR: #{ e . to_s } "
30
- render :file => "#{ RAILS_ROOT } /public/500.html" , :status => 500
40
+ rescue_from ActionController ::RoutingError do |e |
41
+ render :file => "#{ RAILS_ROOT } /public/404.html" , :status => 404
31
42
end
32
43
33
44
helper_method :has_users
@@ -44,7 +55,7 @@ def logged_in?
44
55
end
45
56
return false
46
57
end
47
-
58
+
48
59
def login_required
49
60
if !logged_in?
50
61
redirect_to :controller => "sessions" , :action => "new"
0 commit comments