简体   繁体   中英

Devise how to allow logged user to sign up another user

I want to be able to sign up new user even if I am logged in.

Right now if I click "sign up" while logged in, registration form will not show up. Instead the error message will say "you are already signed in".

I want to allow user(admin) to add new users to the system.

Create a UsersController and authenticate the user as admin . Then in new and create actions of the controller, you can put your user creation logic. And copy the content of views/devise/registration/new.html.erb file to views/users/new.html.erb .

Expanded answer:

You can create a role table if there are more than two roles to manage. That will make it easy to manage them. May be you can you cancan and rolify gems to manage scope for a role if needed.

And if there are only two roles (Admin and other/normal users) then you can add a boolean column admin in the users table .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM