[英]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. 我正在用devise在Rails 3中进行身份验证。登录到主页后,可以通过在应用程序的lib文件夹中创建一个名为custom_failure.rb的文件并在application.rb中添加一些代码来重定向用户。 Following is my custom_failure.rb code
以下是我的custom_failure.rb代码
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 以下是application.rb代码
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
至于建议- https://stackoverflow.com/a/19402686/1125893您可以覆盖
after_sending_reset_password_instructions_path_for(resource_name)
在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 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 在您的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 这基本上是覆盖默认的devise方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.