Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manually create users with Devise

In my rails app, I'm using devise for user registration. Now besides the user registrations, admins should create, edit and delete user in the backend, too. I have a problem with creating new users through that admin backend.

When I call the UsersController#new action in my browser it opens up the user entry form created by me. When I click on the submit button the Devise::RegistrationsController#create is called but it should call my UsersController#create action.

How do I achvieve to call UsersController#create when using the user creation in the admin backend, and to call Devise::RegistrationsController#create when a user uses the registration?

like image 592
Michael Stark Avatar asked May 12 '12 08:05

Michael Stark


People also ask

What is devise authentication?

Devise is a well known solution for authentication in Rails applications. It's full featured (it not only adds authentication but also password recovery, email changing, session timeout, locking, ip tracking, etc.) and can be expanded to add even more (like JWT authentication).


1 Answers

1) add the path prefix to devise: devise_for :users, :path_prefix => 'd'

2) run rake routes:

user_registration POST   /d/users(.:format)   devise/registrations#create
...
users POST   /users(.:format)  users#create

So, the first route for Devise::RegistrationsController, second for your UsersController.

And you can simply use in the admin/new_user.html.erb: form_for User.new

like image 97
Mik Avatar answered Sep 21 '22 18:09

Mik