1

I am using devise for authentication, devise automatically sign in after signing up, i need just sign up but not sign in. There is similar question link but it didn't help me

Community
  • 1
  • 1
Aydar Omurbekov
  • 2,047
  • 4
  • 27
  • 53
  • Why don't you use rolify and cancan gem. Everyone who signs up gets a temporary role, then you can do what you want with those roles. – Benjamin Aug 31 '13 at 06:46

1 Answers1

7

Disclaimer: The following code is not verified in my practice. Just in theory they are likely to work.

At first you need to use your custom RegistrationsController. You can check how to do that in Devise wiki.

After setting up, things are fairly easy. Do the following in your custom controller

class Users::RegistrationsController < Devise::RegistrationsController
  def create
    super #Nothing special here.
  end

  protected

  def sign_up(resource_name, resource)
    true
  end
end

How does it work? In Devise's code, #create will call a protected method #sign_up after saving successfully. This method does nothing but sign in the user. What we need to do is to overwrite this method to stop that action. Of course you can even add more of your logic here if necessary.

Billy Chan
  • 24,625
  • 4
  • 52
  • 68