Rails Generate Devise: controllers do not work

Simple question.

I am using Rails 4.1.4 and Devise 3.3.0 for my application.

I am trying to create Devise controllers so that I can override some actions.

The documentation says you need to run ...

rails generate devise: [scope] controllers

... to create controllers in the application / controllers / area, so you can modify them. But when I run the previous command, he continues to say that the generator is not being developed: controllers:

Could not find generator: controllers.

Does anyone know why?

Thanks.

UPDATE

In fact, when I run ...

rails generate

... to get a list of available generators, I get the following output for Devise generators:

Develop:

Are developing

Develop: install

DEViSE: view

So definitely, the devise: controller generator does not exist. Is there any way to add it ?. How?.

Thanks.

+7
ruby-on-rails devise
source share
3 answers

solvable

I just created a controller manually and inherited it from Devise . For example:

class Users::RegistrationsController < Devise::RegistrationsController # Override the action you want here. end 

This controller must be located in the application / controllers / users / registrations_controller.rb. If you have other options, just log in using applications / controllers / scope / registrations_controller.rb. For example, if you have an administration area, it will be applications / controllers / admins / registrations_controller.rb.

Best.

UPDATE

Following the comment from blushrt, I forgot to mention that it is important to modify config / routes.rb so that make Devise uses the created controller for a specific resource. For example, for users, you should enter your config / routes.rb:

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

What is it. Best.

+13
source share

To answer the original OP question "Does anyone know why?"

The problem is that this generator is currently only available on the Devise main branch, as pointed out in this GitHub issue .

If you want to use this function before publishing it, you can add it to your Gemfile :

 gem 'devise', git: 'https://github.com/plataformatec/devise' 
+3
source share

https://github.com/plataformatec/devise/wiki/Tool:-Generate-and-customize-controllers

You can run this command in your terminal.

 bash <(curl -s https://raw.githubusercontent.com/foohey/cdc/master/cdc.sh) 
+2
source share

All Articles