module Devise::Controllers::Helpers
Those helpers are convenience methods added to ApplicationController.
Public Instance Methods
The default url to be used after signing in. This is used by all Devise
controllers and you can overwrite it in your ApplicationController to provide a custom hook for a custom resource.
By default, it first tries to find a valid resource_return_to key in the session, then it fallbacks to resource_root_path, otherwise it uses the root path. For a user scope, you can define the default url in the following way:
map.user_root '/users', controller: 'users' # creates user_root_path map.namespace :user do |user| user.root controller: 'users' # creates user_root_path end
If the resource root path is not defined, root_path is used. However, if this default is not enough, you can customize it, for example:
def after_sign_in_path_for(resource) stored_location_for(resource) || if resource.is_a?(User) && resource.can_publish? publisher_url else super end end
# File lib/devise/controllers/helpers.rb, line 142 def after_sign_in_path_for(resource_or_scope) stored_location_for(resource_or_scope) || signed_in_root_path(resource_or_scope) end
Method used by sessions controller to sign out a user. You can overwrite it in your ApplicationController to provide a custom hook for a custom scope. Notice that differently from after_sign_in_path_for
this method receives a symbol with the scope, and not the resource.
By default it is the root_path.
# File lib/devise/controllers/helpers.rb, line 152 def after_sign_out_path_for(resource_or_scope) respond_to?(:root_path) ? root_path : "/" end
Tell warden that params authentication is allowed for that specific page.
# File lib/devise/controllers/helpers.rb, line 97 def allow_params_authentication! request.env["devise.allow_params_authentication"] = true end
Return true if it's a devise_controller. false to all controllers unless the controllers defined inside devise. Useful if you want to apply a before filter to all controllers, except the ones in devise:
before_filter :my_filter, unless: :devise_controller?
# File lib/devise/controllers/helpers.rb, line 81 def devise_controller? is_a?(::DeviseController) end
Setup a param sanitizer to filter parameters using strong_parameters. See lib/devise/parameter_sanitizer.rb for more info. Override this method in your application controller to use your own parameter sanitizer.
# File lib/devise/controllers/helpers.rb, line 88 def devise_parameter_sanitizer @devise_parameter_sanitizer ||= if defined?(ActionController::StrongParameters) Devise::ParameterSanitizer.new(resource_class, resource_name, params) else Devise::BaseSanitizer.new(resource_class, resource_name, params) end end
Overwrite Rails' handle unverified request to sign out all scopes, clear run strategies and remove cached variables.
# File lib/devise/controllers/helpers.rb, line 178 def handle_unverified_request sign_out_all_scopes(false) request.env["devise.skip_storage"] = true expire_data_after_sign_out! super # call the default behaviour which resets the session end
Check if flash messages should be emitted. Default is to do it on navigational formats
# File lib/devise/controllers/helpers.rb, line 195 def is_flashing_format? is_navigational_format? end
# File lib/devise/controllers/helpers.rb, line 185 def request_format @request_format ||= request.format.try(:ref) end
Sign in a user and tries to redirect first to the stored location and then to the url specified by after_sign_in_path_for. It accepts the same parameters as the sign_in method.
# File lib/devise/controllers/helpers.rb, line 159 def sign_in_and_redirect(resource_or_scope, *args) options = args.extract_options! scope = Devise::Mapping.find_scope!(resource_or_scope) resource = args.last || resource_or_scope sign_in(scope, resource, options) redirect_to after_sign_in_path_for(resource) end
Sign out a user and tries to redirect to the url specified by after_sign_out_path_for.
# File lib/devise/controllers/helpers.rb, line 169 def sign_out_and_redirect(resource_or_scope) scope = Devise::Mapping.find_scope!(resource_or_scope) redirect_path = after_sign_out_path_for(scope) Devise.sign_out_all_scopes ? sign_out : sign_out(scope) redirect_to redirect_path end
The scope root url to be used when they're signed in. By default, it first tries to find a resource_root_path, otherwise it uses the root_path.
# File lib/devise/controllers/helpers.rb, line 103 def signed_in_root_path(resource_or_scope) scope = Devise::Mapping.find_scope!(resource_or_scope) home_path = "#{scope}_root_path" if respond_to?(home_path, true) send(home_path) elsif respond_to?(:root_path) root_path else "/" end end
The main accessor for the warden proxy instance
# File lib/devise/controllers/helpers.rb, line 72 def warden request.env['warden'] end
Private Instance Methods
Devise::Controllers::SignInOut#expire_data_after_sign_out!
# File lib/devise/controllers/helpers.rb, line 207 def expire_data_after_sign_out! Devise.mappings.each { |_,m| instance_variable_set("@current_#{m.name}", nil) } super end
# File lib/devise/controllers/helpers.rb, line 201 def expire_session_data_after_sign_in! ActiveSupport::Deprecation.warn "expire_session_data_after_sign_in! is deprecated " \ "in favor of expire_data_after_sign_in!" expire_data_after_sign_in! end