设计模型确认后做自定义动作

typ*_*ror 2 ruby ruby-on-rails devise devise-confirmable

我知道一旦用户确认了一个Confirmable帐户,我可以用以下内容更改重定向网址:

def after_confirmation_path_for(resource)
  view_context.admin_dashboard_url_for(subdomain: resource.tenant.subdomain)
end
Run Code Online (Sandbox Code Playgroud)

但是如果我想resource在确认之后调用自定义方法,我将如何使用设计?我想我可以坚持这种方法......

 def after_confirmation_path_for(resource)
   resource.do_thing_after_confirmation
   view_context.admin_dashboard_url_for(subdomain: resource.tenant.subdomain)
 end
Run Code Online (Sandbox Code Playgroud)

但是这种方法改变模型并不合适.

typ*_*ror 5

我发现在方法Devise::Models::Confirmable调用了一个空白confirm!方法.我将在我的用户资源模型中覆盖此方法并在此处完成我的工作.

def after_confirmation
end
Run Code Online (Sandbox Code Playgroud)