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

时间:2018-09-25 15:46:45

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

我需要更改此资源

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

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

谢谢!

1 个答案:

答案 0 :(得分:0)

Devise具有很多固有的内置功能。<​​/ p>

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

在这种情况下,您想要一个从devise conf contr继承的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

这应该会让您入门,请检查devise文档,因为它们非常可靠。