Search code examples
ruby-on-railsrubydevisedevise-confirmable

Do custom action after devise model confirmation


I know once the user has confirmed a Confirmable account in devise, I can change the redirect URL with:

def after_confirmation_path_for(resource)
  view_context.admin_dashboard_url_for(subdomain: resource.tenant.subdomain)
end

But if I wanted to call a custom method on the resource after confirmation, how would I do that with devise? I suppose I could stick it in this method...

 def after_confirmation_path_for(resource)
   resource.do_thing_after_confirmation
   view_context.admin_dashboard_url_for(subdomain: resource.tenant.subdomain)
 end

But that doesn't feel right to have this method changing the model.


Solution

  • I found a blank method in Devise::Models::Confirmable that is called during the confirm! method. I'm going to override this method in my User resource model and do my work here.

    def after_confirmation
    end