我发现的所有问题都与使用助手成功登录有关
after_sign_in_path_for(资源)
我的网站索引中有一个登录表单,当登录失败时,它会重定向到“users/sign_in”
但是当登录失败时如何重定向到我的site#index
?
最佳答案
在您的 lib 目录中创建一个 custom_failure.rb,其中包含:
class CustomFailure < Devise::FailureApp def redirect_url your_path end def respond if http_auth? http_auth else redirect end end end
在您的 Devise 初始化程序中,包括:
config.warden do |manager| manager.failure_app = CustomFailure end
确保 Rails 正在加载您的 lib 文件,application.rb :
config.autoload_paths += %W(#{config.root}/lib)
不要忘记重新启动服务器。
我认为没有更简单的方法可以做到这一点。
关于ruby-on-rails - 设计登录失败后重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5832631/