I have a Rails 3 project with Devise, confirmable enabled so the user has to confirm their account through email after registration. Currently the project returns the user to the login page and throws a "You've signed up successfully..." notice. What I want to do instead is redirect them to a "thank you" page, with further instructions (check your email, spam folder, blah blah).
My first stop was the Devise wiki, where I found this page. Looked easy enough, I made the following alterations and followed the directions exactly...
/app/controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
"http://google.com"
end
end
/config/routes.rb
devise_for :users, :controllers => { :registrations => "registrations" }
The one modification I had to make over the direction was moving the "registrations" folder out of the /app/views/devise view folder and into the top /app/views folder, as an error returned that the views were now missing. Anyway, despite the controller override appearing to work (I don't think the views would have originally broken otherwise), those directions do NOT work...the page ignores the after_sign_up and returns to the login page after signing up.
Went hunting on the internet including other Stack Overflow threads, but nothing I found has worked for me...either answers confuse redirecting sign up for sign IN, or what they're actually doing is changing the redirect after sign in (as Devise normally automatically signs in after registration without confirmable enabled).
Other things I have tried...
Moving the after_sign_up_path_for(resource) into the application controller. Doesn't work. Oddly enough, doing the same with after_sign_in_path_for(resource) and signing in as a user DOES redirect.
Moving the registrations_controller.rb from /app/controllers/ into /app/controllers/users folder and updating all routes/references/etc accordingly. No go.
Copying Devise's registrations_controller.rb into my own registrations_controller.rb. Didn't work, just threw up an error and I rolled it all back.
I tried def after_inactive_sign_up_path_for(resource), as I thought maybe the fact that the account wasn't active yet was the culprit. This is also ignored.
It's also worth mentioning I have tried restarting my project after these major changes, but nothing takes.
Has anyone had any success with pulling this off with confirmable enabled?
I'm just putting @Shannon's comment into an answer to make it easier to find.
If you are requiring email confirmation after sign-up, your user will be left in an in-between state where they have signed up but not clicked the link emailed to them to confirm their account. This is an inactive sign up. To redirect in this situation you need to specify:
def after_inactive_sign_up_path_for(resource)
"http://example.com"
end
Which version of devise are you using? I'm pretty sure that this issue was recently resolved so you probably need the latest version from the repo which is still a release candidate (although it should be out soon as they were waiting for omniauth 0.2 to get out of beta which recently happened).
I am using Devise 1.2.rc2 from the github repo with rails 3.0.5. I added the code that you mentioned to my custom RegistrationsController and was forwarded to google as expected after creating a new account.
A cutdown version of my RegistrationsController (in app/controllers/users)
class Users::RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
"http://google.com"
end
end
My routes.rb entry
devise_for :users, :controllers => { :registrations => "users/registrations" }
From my Gemfile
gem 'devise', :git => "git://github.com/plataformatec/devise.git"
Let me know if you're having problems on the latest version of devise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With