Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect a user after registration when using Devise?

I am using Rails 2.3 and Devise to handle user registration / authentication.

I need to redirect a user to an external 3rd party website immediately after a user signs up for an account. Been looking in the code & online but cannot see how to do this.

How can I alter the devise flow to redirect the user?

like image 929
Jason Avatar asked Aug 29 '10 01:08

Jason


3 Answers

The answer listed as the "correct" answer specifically refers to after sign_in... If you want to do redirect a user after sign_up you need to override the following:

def after_sign_up_path_for(resource)
  "http://www.google.com" # <- Path you want to redirect the user to after signup
end

Full details can be found on the wiki.

like image 50
Brett Hardin Avatar answered Oct 15 '22 19:10

Brett Hardin


Add to your Application Controller

  # Devise: Where to redirect users once they have logged in
  def after_sign_up_path_for(resource)
    "http://www.google.com" # <- Path you want to redirect the user to.
  end

Here is the list of Devise helpers you can use http://rdoc.info/github/plataformatec/devise/master/Devise/Controllers/Helpers

I hope that helps =)

like image 24
Carlos A. Cabrera Avatar answered Oct 15 '22 21:10

Carlos A. Cabrera


If you are using Devise's confirmations (meaning the user is not activated immediately after they sign up), you need to overwrite the after_inactive_sign_up_path_for method.

# controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
  def after_inactive_sign_up_path_for(resource)
    "http://somewhere.com"
  end
end

Make sure to tell devise to use your RegistrationsController.

# config/routes.rb
devise_for :users, :controllers => {:registrations => 'registrations'}
like image 40
declan Avatar answered Oct 15 '22 20:10

declan