0

I have devise and cancan set up and I'm having trouble redirecting users to a certain page after registration.

class RegistrationsController < Devise::RegistrationsController
  def after_sign_up_path_for(resource)
    "http://google.com"
  end
end

then in my routes:

  authenticated :user do
    root :to => "dashboard#show"
  end

Now when I sign up a user, it just gets directed to the dashboard#show. I'm trying to make it go to google.com, but it doesn't. Am I doing something wrong? Or is there another way to redirect users after signing up when using CanCan?

Thanks

hellomello
  • 8,219
  • 39
  • 151
  • 297

3 Answers3

0

Devise Wiki -> How To: Redirect to a specific page on successful sign up (registration)

Mini John
  • 7,855
  • 9
  • 59
  • 108
0

You add to your application_controller.rb

 def after_sign_up_path_for(resource)
   "http://google.com"
 end

source : redirec_to external_url

Or you can use certain external link on route looks like

# in `config/routes.rb` :

match "/google" => redirect("http://google.com"), :as => :google

# in `registrations_controller.rb` :

def after_sign_up_path_for(resource)
   google_path
end 

If you are using Devise's confirmations (the user is not activated after they sign up), you can use after_inactive_sign_up_path_for method.

# controllers/registrations_controller.rb

class RegistrationsController < Devise::RegistrationsController


  def after_inactive_sign_up_path_for(resource)
    "http://google.com"
  end

end
rails_id
  • 8,120
  • 4
  • 46
  • 84