Rails 4 and creating new users

56 views
Skip to first unread message

Arr Emm

unread,
Mar 25, 2015, 4:53:09 AM3/25/15
to plataforma...@googlegroups.com
I decided to stop copy/pasting my rails 3 app and to create a new rails 4 app to copy and paste long into the future (thus avoiding the ever looming elephant in the room).  I'm having trouble sorting out where user creation takes place with devise.  I tried doing some `rails g devise:controllers` and then `rails g devise:controllers users` and updated config/routes.rb to be

devise_for :users, controllers: { sessions: "users/sessions",
                                    registrations
: "users/registrations" }

I'm still not able to stop rails in the controller to investigate further problems with starting new rails apps... the output. 

# app/controllers/users/registrations_
class Users::RegistrationsController < Devise::RegistrationsController
# before_filter :configure_sign_up_params, only: [:create]
# before_filter :configure_account_update_params, only: [:update]

 
# GET /resource/sign_up
 
# def new
 
#   super
 
# end

 
# POST /resource
 
def create
    binding
.pry
   
super
 
end

LOL
!  I can't escape from the code section!  This is not my night for technology!  Anyway, is there a trick to finding out where code paths go in the latest devise?  Thanks!


Carlos Antonio da Silva

unread,
Mar 25, 2015, 6:57:39 AM3/25/15
to Devise
In theory the registrations controller is where users are created/signed up, so you should be able to use that. Have you tried restarting your server?

--

---
You received this message because you are subscribed to the Google Groups "Devise" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plataformatec-de...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
At.
Carlos Antonio

Arr Emm

unread,
Mar 25, 2015, 12:50:32 PM3/25/15
to plataforma...@googlegroups.com
Oops, it seems like just putting:

# config/routes.rb
devise_for :users, controllers: {
    sessions: 'users/sessions'
  }


After generating those controllers was enough to fix it.  I was getting an unstyled flash error message stating I was already logged in and so the controller that was reportedly being run

Started POST "/users" for 127.0.0.1 at 2015-03-25 11:38:21 -0500
Processing by Devise::RegistrationsController#create as HTML

Was actually returning and rendering short, before it got to any of the code in the controller.  This leaves me wondering how to edit the code to allow admins to create users without needing to log out first.  Is there a trick to doing that?  I'd like to make it so only the admin user is able to make new users if that can be done quickly, or at the very least allow them to make users without needing to explicitly log off before doing so all in a single post request to `Devise::RegistrationsController#create`. 
To unsubscribe from this group and stop receiving emails from it, send an email to plataformatec-devise+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
At.
Carlos Antonio

Carlos Antonio da Silva

unread,
Mar 25, 2015, 12:56:56 PM3/25/15
to Devise
My recommendation is: do not use the registrations logic provided by devise, they are meant for user sign up logic, not for the use case of admins creating new users.

Just go ahead and create a new users controller by yourself, where the admin can add/remove users. It will be way simpler, you won't have to mess up with devise internals and things like who is signed in/out and so on.

Hope that helps.

To unsubscribe from this group and stop receiving emails from it, send an email to plataformatec-de...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
At.
Carlos Antonio

Arr Emm

unread,
Mar 25, 2015, 1:27:25 PM3/25/15
to plataforma...@googlegroups.com
Yes thank you!  I was a little unsure how to carry that out, but I wound up pointing it out to my app in config/routes.rb so that it now uses my existing users_controller.rb
To unsubscribe from this group and stop receiving emails from it, send an email to plataformatec-devise+unsubscrib...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
At.
Carlos Antonio

--

---
You received this message because you are subscribed to the Google Groups "Devise" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plataformatec-devise+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
At.
Carlos Antonio

Walter Lee Davis

unread,
Mar 25, 2015, 7:15:06 PM3/25/15
to plataforma...@googlegroups.com

On Mar 25, 2015, at 12:56 PM, Carlos Antonio da Silva <carlosanto...@gmail.com> wrote:

> My recommendation is: do not use the registrations logic provided by devise, they are meant for user sign up logic, not for the use case of admins creating new users.
>
> Just go ahead and create a new users controller by yourself, where the admin can add/remove users. It will be way simpler, you won't have to mess up with devise internals and things like who is signed in/out and so on.
>
> Hope that helps.

I'm a huge fan of devise_invitable for this workflow, because you can then make a new user, and not set their password. The user gets to make their own password and the only thing you have to do is press a button to send a welcome e-mail.

Walter
Reply all
Reply to author
Forward
0 new messages