Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 and Devise: Redirecting to page following signup (confirmable)

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...

  1. 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.

  2. Moving the registrations_controller.rb from /app/controllers/ into /app/controllers/users folder and updating all routes/references/etc accordingly. No go.

  3. 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.

  4. 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.

  5. 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?

like image 217
Shannon Avatar asked Mar 28 '11 17:03

Shannon


2 Answers

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
like image 186
Undistraction Avatar answered Oct 18 '22 15:10

Undistraction


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.

like image 22
Braden Becker Avatar answered Oct 18 '22 14:10

Braden Becker