How to manually create users using Devise

In my rails application, I use a program to register a user. Now, in addition to registering users, administrators must create, edit and delete the user in the backend. I had a problem creating new users through this admin server.

When I call the new UsersController # new action in my browser, it opens the user input form I created. When I click the submit button, Devise :: RegistrationsController # create is called, but it should call the MyController # create action.

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

+5
source share
2 answers

1) add the development path prefix: 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, the second for yours UsersController.

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

+5
source

On the back of Michaelโ€™s answer, you can also say that you need to use any other path name instead of โ€œusersโ€. For instance:

devise_for :users, path: 'auth'

will lead to the development of routes such as / auth / sign _up, / auth / sign_in, etc. And your custom routes will be safe.

( devise_for )

0

All Articles