设计:重新注册失败? [英] Devise: redirect on sign up failure?
问题描述
我正在尝试重定向注册表单失败的用户(例如,他们输入已经被使用的用户名,他们留下了一个字段空白等)。
I'm trying to redirect users that have failed the sign up form (e.g. they entered a username that is already taken, they left a field blank, etc...)
我为无法登录表单的用户设置了自定义失败,代码如下:
I have custom failure set up for users that fail the sign in form, code below:
class CustomFailure < Devise::FailureApp
def redirect_url
root_path
end
def respond
if http_auth?
http_auth
else
redirect
end
end
但是,我一直坚持如何设置这个注册失败。理想情况下,我只想将它们重定向到/ root_path,任何想法?谢谢!
However, I've been stuck on how to set this up for sign up failure. Ideally I would just like to redirect them back/to root_path, any ideas? Thank you!
推荐答案
您可能需要子类 Devise :: RegistrationsController
并覆盖创建操作。只需复制此处的创建方法,并在修改重定向失败保存。
You will probably need to subclass Devise::RegistrationsController
and override the create action. Just copy over the create method from here and modify the redirect on failure to save.
# app/controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
def create
# modify logic to redirect to root url
end
end
更改路线,告诉Devise使用您的控制器:
Change your routes to tell Devise to use your controller:
# config/routes.rb
devise_for :users, :controllers => {:registrations => "registrations"}
这篇关于设计:重新注册失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!