我在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)
请通过指定我应覆盖哪个重定向功能来帮助我,以便在重置密码邮件发送后将用户重定向到登录页面。谢谢
答案 0 :(得分:2)
根据建议 - 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
#routes.rb
devise_for :users, :controllers => { :passwords => "passwords" }
答案 1 :(得分:0)
尝试
if http_auth?
redirect_to http_auth
else
redirect_to redirect_url
end
答案 2 :(得分:0)
在你的application_controller.rb
中protected
def after_sending_reset_password_instructions_path_for(resource_name)
#set your path here
end
这基本上覆盖了默认设计方法