确认后如何使设计重定向 [英] How to make Devise redirect after confirmation
问题描述
如何在 Devise 中创建确认后重定向?
How can I create an after-confirmation redirect in Devise?
在我添加 confirmation module
之前,自定义 after_sign_up_path
第一次运行正常 login/signup
但现在当我点击确认链接时在电子邮件中,它重定向到我为登录后路径(用户配置文件)设置的路径.
Before I added the confirmation module
the custom after_sign_up_path
worked fine for the first time login/signup
but now when I click the confirmation link in the email it redirects to the path I set for the after-login path (user profile).
我的目标是创建一个表单向导和入门"页面来收集更多信息.明显的警告是,在确认后,此重定向只会发生一次.
My goal is to create a form wizard and "getting started" page to collect additional information. The obvious caveat being that this redirect will only happen one time, upon confirmation.
我尝试了 Stack Overflow 上发布的一些其他解决方案,但它们似乎都不再有效.
I tried some other solutions that have been posted on Stack Overflow but none of them seem to work any longer.
推荐答案
本质上,你想要改变Devise 的 ConfirmationsController
的第 25 行.
Essentially, you want to change around line 25 of Devise's ConfirmationsController
.
这意味着您需要覆盖 show
操作,修改 show
操作中的 if
语句的快乐路径",以达到您的目的内容:
This means you need to override the show
action modifying the "happy path" of that if
statement in the show
action to your heart's content:
class ConfirmationsController < Devise::ConfirmationsController
def new
super
end
def create
super
end
def show
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
if resource.errors.empty?
set_flash_message(:notice, :confirmed) if is_navigational_format?
sign_in(resource_name, resource)
respond_with_navigational(resource){ redirect_to confirmation_getting_started_path }
else
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render_with_scope :new }
end
end
end
以及它的作用域路由(我将视图和操作放在了注册控制器中,但您可以将其更改为任何内容):
And a scoped route for it (I put the view and action in the registrations controller but you can change it to whatever):
devise_for :users, controllers: { confirmations: 'confirmations' }
devise_scope :user do
get '/confirmation-getting-started' => 'registrations#getting_started', as: 'confirmation_getting_started'
end
默认的 show
操作是指受保护的 after_confirmation_path_for
方法,因此作为另一种选择,您可以修改该方法返回的内容.
The default show
action is referring to the protected after_confirmation_path_for
method, so as another option, you could just modify what that method returns.
这篇关于确认后如何使设计重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!