我正在尝试重定向未通过注册表单的用户(例如,他们输入的用户名已被占用,他们将字段留空等...)
我为登录表单失败的用户设置了自定义失败,代码如下:
class CustomFailure < Devise::FailureApp
def redirect_url
root_path
end
def respond
if http_auth?
http_auth
else
redirect
end
end
但是,我一直在研究如何针对注册失败进行设置。理想情况下,我只想将它们重定向回/到 root_path,有什么想法吗?谢谢!
最佳答案
您可能需要子类化 Devise::RegistrationsController
并覆盖创建操作。只需从 here 复制创建方法即可并在保存失败时修改重定向。
# app/controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
def create
# modify logic to redirect to root url
end
end
改变你的路由来告诉 Devise 使用你的 Controller :
# config/routes.rb
devise_for :users, :controllers => {:registrations => "registrations"}
关于ruby-on-rails - 设计:注册失败时重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6240141/