Rails Device Confirmable – How to Redirect to a Different URL Than Root After Signup

I implemented the confirmable module of Rails Devise gem. After a user signs up for a new account, the default behavior is that they are redirected to the root path and shown a flash message.

However, I didn’t want to redirect my users to the root path because this page is one that I wanted to remain completely static for performance reasons. In other words, I didn’t want to show flash messages there, so I cache the same page to every user.

There was a lot of documentation on how to redirect users after signup, but it was for when confirmable wasn’t being used. There was also documentation on how to redirect users after they confirmed, but I wanted to redirect users before they confirmed.

The solution was to overwrite the Registrations controller like this (in a registrations_controller.rb file):

class Users::RegistrationsController < Devise::RegistrationsController
 
 protected

 def after_inactive_sign_up_path_for(resource)
     new_user_session_path
   end
 end