如何在Deave中创建确认后重定向?
在我添加confirmation module
之前,自定义after_sign_up_path
第一次运行良好login/signup
,但现在当我单击邮箱中的确认链接时,它会重定向到我为登录后路径(用户配置文件)设置的路径.
我的目标是创建一个表单向导和"入门"页面来收集更多信息.显而易见的警告是,这种重定向只会在确认后发生一次.
我try 了其他一些已发布在Stack Overflow上的解决方案,但它们似乎都不再有效.
如何在Deave中创建确认后重定向?
在我添加confirmation module
之前,自定义after_sign_up_path
第一次运行良好login/signup
,但现在当我单击邮箱中的确认链接时,它会重定向到我为登录后路径(用户配置文件)设置的路径.
我的目标是创建一个表单向导和"入门"页面来收集更多信息.显而易见的警告是,这种重定向只会在确认后发生一次.
我try 了其他一些已发布在Stack Overflow上的解决方案,但它们似乎都不再有效.
基本上,你想改变Deave ConfirmationsController
中的大约line 25个.
这意味着您需要覆盖show
个动作,将show
个动作中if
条语句的"快乐路径"修改为您内心的内容:
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
以及它的作用域路由(我将视图和操作放在注册控制器中,但您可以将其更改为任何内容):
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
方法,因此作为另一个选项,您可以修改该方法返回的内容.