Class: ApplicationController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- ApplicationController
- Defined in:
- app/controllers/application_controller.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#authorize(redirect = nil) ⇒ Object
redirect: Path to login page.
- #current_account ⇒ Object
- #redirect ⇒ Object
- #set_current_account ⇒ Object
Instance Method Details
#authorize(redirect = nil) ⇒ Object
redirect: Path to login page.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/application_controller.rb', line 7 def (redirect=nil) # Not using skip_before_filter, since main app could inadvertently override that # by using a before_filter :authorize in its application_controller. if params[:controller] == 'accounts' && ['do_login', 'login', 'do_logout', 'do_signup', 'signup'].include?(params[:action]) return true end if current_account.nil? session[:redirect] = url_for params redirect_to redirect || login_path, alert: 'Please log in to access this page.' else return true end end |
#current_account ⇒ Object
22 23 24 |
# File 'app/controllers/application_controller.rb', line 22 def current_account @current_account end |
#redirect ⇒ Object
36 37 38 39 |
# File 'app/controllers/application_controller.rb', line 36 def redirect session_redirect = session.delete(:redirect) redirect_to params[:redirect] || session_redirect || root_path end |
#set_current_account ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/application_controller.rb', line 26 def set_current_account if session[:account_id].nil? @current_account = nil elsif @current_account.nil? || @current_account.id != session[:account_id] @current_account = Account.find session[:account_id] end true end |