Search code examples
ruby-on-railsdevisedevise-confirmable

Redirect user to certain page after registration using Devise + confirmable


I am using Devise for user registration, and am using Confirmable to perform email validation.

After a user registers, I want to redirect them to a URL explaining that they need to check their email and click on the link sent. I am using Devise's :authenticate_user! method to ensure users log in before seeing site content.

Per this file, it looks like I can define a after_inactive_sign_up_path_for(resource) and a after_sign_up_path_for(resource) to control this redirect.

Here is my application controller:

class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :authenticate_user!, :except => [:after_inactive_sign_up_path_for,     :after_sign_up_path_for]

def after_sign_up_path_for(user)
  confirm_path
end

def after_inactive_sign_up_path_for(user)
  confirm_path
end

end 

But it doesn't work. confirm_path is in my static_pages controller, which is accessible without signin as I have skip_before_filter :authenticate_user! included

When a user registers, the :authenticate_user! helper kicks in and redirects to the login page.


Solution

  • Have you tried overriding the registration controller like so :

    class RegistrationsController < Devise::RegistrationsController
      protected
    
      def after_inactive_sign_up_path_for(resource)
        '/an/example/path'
      end
    end
    

    https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-up-(registration)