繁体   English   中英

使用devise在Rails 3中发送密码重置说明后,如何将用户重定向到登录页面

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

我正在用devise在Rails 3中进行身份验证。登录到主页后,可以通过在应用程序的lib文件夹中创建一个名为custom_failure.rb的文件并在application.rb中添加一些代码来重定向用户。 以下是我的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

以下是application.rb代码

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

请通过指定重设哪个重定向功能来帮助我,以便在发送重置密码邮件后将用户重定向到登录页面。

至于建议- 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

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

试试看

if http_auth?
   redirect_to http_auth
  else
   redirect_to redirect_url
  end

在您的application_controller.rb中

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

这基本上是覆盖默认的devise方法

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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