首页 > 解决方案 > 如何在 Devise Rails 5 上更改 @resource 确认 URL?

问题描述

我需要更改此资源

<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %> </p>

我不需要重定向到令牌路径,只需在用户确认电子邮件后重定向到 root_path

谢谢!

标签: ruby-on-railsruby-on-rails-5

解决方案


Devise 有很多内置的功能。

为了改变它的行为,你必须隐式地覆盖它的行为或以某种方式修改它。

在这种情况下,您希望有一个从 devise conf contr 继承的 Confirmations 控制器。在里面你想

class ConfirmationsController < Devise::ConfirmationsController

# some other code if you want to change how certain views behave 


private

def after_confirmation_path_for(resource)
  sign_in(resource) # signs in the user at confirmation


  # does whatever you want after the user is singed in at the confirmation 
  # - this is where you may want to redirect or whatever you desire
  after_sign_in_path_for(resource) 
end

end

在应用程序控制器中定义 after_sign_in_path_for

您可以执行以下操作:

def after_sign_in_path_for(resource)
 root_path
end

这应该可以帮助您入门,请检查设计文档,因为它们非常可靠。


推荐阅读