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?
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) 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With