Module: Ninsho::Controllers::Helpers
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/ninsho/controllers/helpers.rb
Constant Summary collapse
- RESOURCE_NAME =
Ninsho.resource_name.singularize
- PARENT_RESOURCE_NAME =
Ninsho.parent_resource_name.to_s.downcase
Instance Method Summary collapse
-
#clear_return_to ⇒ Object
Clears the session after redirection is done.
-
#deny_access ⇒ Object
Redirection if user has no right to enter.
-
#redirect_back_or(default) ⇒ Object
Method which handles the redirection.
- #redirect_on_sign_in_path ⇒ Object
-
#redirect_on_sign_out_path ⇒ Object
Method used by sessions controller to sign out a user.
- #redirect_to_root ⇒ Object
-
#sign_in(parent_id) ⇒ Object
Set the session for the authenticated user.
- #sign_in_and_redirect(parent_id, path = nil) ⇒ Object
-
#sign_out ⇒ Object
Destroy the user session.
-
#store_location ⇒ Object
Stores the location for better redirection.
Instance Method Details
#clear_return_to ⇒ Object
Clears the session after redirection is done
15 16 17 |
# File 'lib/ninsho/controllers/helpers.rb', line 15 def clear_return_to session[:return_to] = nil end |
#deny_access ⇒ Object
Redirection if user has no right to enter
83 84 85 |
# File 'lib/ninsho/controllers/helpers.rb', line 83 def deny_access redirect_to_root end |
#redirect_back_or(default) ⇒ Object
Method which handles the redirection
20 21 22 23 |
# File 'lib/ninsho/controllers/helpers.rb', line 20 def redirect_back_or(default) redirect_to(session[:return_to] || default ) clear_return_to end |
#redirect_on_sign_in_path ⇒ Object
75 76 77 |
# File 'lib/ninsho/controllers/helpers.rb', line 75 def redirect_on_sign_in_path redirect_to_root end |
#redirect_on_sign_out_path ⇒ Object
Method used by sessions controller to sign out a user. You can overwrite it in your ApplicationController
By default it is the root_path.
71 72 73 |
# File 'lib/ninsho/controllers/helpers.rb', line 71 def redirect_on_sign_out_path redirect_to_root end |
#redirect_to_root ⇒ Object
78 79 80 |
# File 'lib/ninsho/controllers/helpers.rb', line 78 def redirect_to_root redirect_to respond_to?(:root_path) ? root_path : "/" end |
#sign_in(parent_id) ⇒ Object
Set the session for the authenticated user
36 37 38 |
# File 'lib/ninsho/controllers/helpers.rb', line 36 def sign_in(parent_id) session["#{PARENT_RESOURCE_NAME}_id".to_sym] = parent_id end |
#sign_in_and_redirect(parent_id, path = nil) ⇒ Object
30 31 32 33 |
# File 'lib/ninsho/controllers/helpers.rb', line 30 def sign_in_and_redirect(parent_id, path=nil) session["#{PARENT_RESOURCE_NAME}_id".to_sym] = parent_id redirect_to path end |
#sign_out ⇒ Object
Destroy the user session
26 27 28 |
# File 'lib/ninsho/controllers/helpers.rb', line 26 def sign_out session["#{PARENT_RESOURCE_NAME}_id".to_sym] = nil end |
#store_location ⇒ Object
Stores the location for better redirection
10 11 12 |
# File 'lib/ninsho/controllers/helpers.rb', line 10 def store_location session[:return_to] = request.fullpath end |