'How to generate Registration controller of devise gem

I have setup Devise, I have set up the below code in my user.rb file

  def self.create_auto_password
    generated_password = Devise.friendly_token.first(8)
    self.create(password: generated_password, password_confirmation: generated_password)
  end

I then tried to generate a registrations controller by running

rails generate devise:controllers -c registrations

and a few other variations but it won't generate... what is the correct command to create a registrations controller in Devise?



Solution 1:[1]

The command you are using has a typo. It should be as shown below:

rails generate devise:controllers users -c=sessions

Hope that helps.

Solution 2:[2]

To generate Devise registration controller only for users use:

rails g devise:controllers users -c=registrations

o/p:

enter image description here

To generate all devise controllers for users use:

rails g devise:controllers users

o/p: enter image description here

Now for actually start using you generated devise controllers modify routes.rb according to generated controller Ex:

for registration do

  devise_for :users, controllers: {
      registrations: 'users/registrations'
  }

and for registrations and sessions do:

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 suretrust
Solution 2