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
Asked
Active
Viewed 2,204 times
1
-
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 Answers
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
-
by adding this into the custom controller auto sign-in will be disabled ? – Mostafa Hussein Aug 31 '13 at 08:58
-
-
A handy tool to generate the controllers: https://github.com/plataformatec/devise/wiki/Tool:-Generate-and-customize-controllers – rohaldb Feb 21 '17 at 08:16