Class ApplicationController
In: app/controllers/application.rb
Parent: ActionController::Base

Filters added to this controller will be run for all controllers in the application. Likewise, all the methods added will be available for all controllers.

Copyright (c) 2006 Logica

Methods

Protected Instance methods

The authenticate method is used as a before_hook in controllers that require the user to be authenticated. If the session does not contain a valid user, the method redirects to the LoginController.login.

[Source]

    # File app/controllers/application.rb, line 56
56:   def authenticate #:doc:
57:     unless session['user']
58:       logger.debug('No session, redirecting to login')
59:       session['return_to'] = request.request_uri
60:       redirect_to :controller => 'login' 
61:       return false
62:     end
63:   end

[Source]

    # File app/controllers/application.rb, line 65
65:   def authenticate_admin #:doc:
66:     logger.debug("Authenticate admin #{session['user']}, #{session['user'].inspect}")
67:     if  !admin?
68:       logger.debug("User not authenticated as admin")
69:       flash['notice'] = 'Administrators privileges are required to access this function'
70:       flash['error'] = LoginController::FLASH_UNOT_ADMIN # TODO should be flash.now?
71:       Notifier::deliver_authorisation_problem(session['user'], session.instance_variable_get("@data"), params, request.env)
72:       redirect_to :controller => 'other', :action => 'error'
73:       return false        
74:     end
75:   end

[Source]

    # File app/controllers/application.rb, line 77
77:   def authenticate_cadmin #:doc:
78:     if  !cadmin?
79:       flash['notice'] = 'You need to be the central administrator to access this function'
80:       flash['error'] = LoginController::FLASH_UNOT_CADMIN
81:       Notifier::deliver_authorisation_problem(session['user'], session.instance_variable_get("@data"), params, request.env)
82:       redirect_to :controller => 'other', :action => 'error'
83:       return false
84:     end
85:   end

instead of an error stack we want to display a nice user friendly error message

[Source]

    # File app/controllers/application.rb, line 45
45:   def local_request? #:doc:
46:     false
47:   end

[Source]

    # File app/controllers/application.rb, line 23
23:   def log_error(exception) #:doc:
24:     super(exception)
25:     begin
26:       # TODO don't send error email when action error causes an error 
27:       Notifier.deliver_error_report(exception, clean_backtrace(exception), 
28:       session.instance_variable_get("@data"), 
29:       params, 
30:       request.env)
31:     rescue => e
32:       logger.error(e)
33:     end
34:   end

all exceptions are redirected to OtherController.error

[Source]

    # File app/controllers/application.rb, line 37
37:   def rescue_action_in_public(exception) #:doc:
38:     flash['error'] = exception.message
39:     flash['notice'] = "An application error occurred while processing your request. This error was logged and an email was sent to notify the administrator."
40:     flash['notice'] = 'We\'re sorry, but something went wrong. We\'ve been notified about this issue and we\'ll take a look at it shortly.'
41:     redirect_to :controller => 'other', :action => 'error'
42:   end

[Validate]