1

我在 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)

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

4

3 回答 3

3

正如建议的那样 - 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" }
于 2013-10-16T08:05:56.157 回答
0

在你的 application_controller.rb

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

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

于 2013-10-16T11:53:24.197 回答
0

尝试

if http_auth?
   redirect_to http_auth
  else
   redirect_to redirect_url
  end
于 2013-10-16T06:59:42.923 回答