繁体   English   中英

如何在Devise Rails 5上更改@resource Confirmation_url?

[英]How to Change @resource confirmation_url on Devise Rails 5?

我需要更改此资源

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

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

谢谢!

Devise具有许多固有的内置功能。

为了更改其行为,您必须隐式覆盖其行为或以某种方式对其进行修改。

在这种情况下,您需要一个从devise conf conctr继承的Confirmation控制器。 在里面你想

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM