简体   繁体   中英

How to redirect the user to login page after sending password reset instructions in rails 3 using devise

I am using devise for authentication in Rails 3. I was able to redirect the user after signing in to the home page by creating a file named custom_failure.rb inside lib folder of my app and adding some code in application.rb. Following is my custom_failure.rb code

class CustomFailure < Devise::FailureApp

 def redirect_url
  root_path
 end

 def respond
  if http_auth?
   http_auth
  else
   redirect
  end
 end

end

Following is the application.rb code

config.autoload_paths += %W(#{config.root}/lib)

Please help me out by specifying which redirect function should I override in order to redirect the user to login page after the reset password mail is sent.Thanks

As suggested - https://stackoverflow.com/a/19402686/1125893 You can override after_sending_reset_password_instructions_path_for(resource_name) in Devise::PasswordController

def after_sending_reset_password_instructions_path_for(resource_name)
  root_path
end

https://github.com/plataformatec/devise/wiki/How-To:-Redirect-URL-after-sending-reset-password-instructions

#routes.rb
devise_for :users, :controllers => { :passwords => "passwords" }

Try with

if http_auth?
   redirect_to http_auth
  else
   redirect_to redirect_url
  end

In your application_controller.rb

protected
def after_sending_reset_password_instructions_path_for(resource_name)
  #set your path here
end

This is basically overriding the default devise method

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM