Controller and Scaffold Controller generator - plural vs. singular

Hello,

Why does:

$ rails g controller project

Generates app/controllers/project_controller.rb

and

$ rails g scaffold_controller project

Generates app/controllers/projects_controller.rb and app/views/projects/?

With scaffold_controller there is even the following message at the end: “Plural version of the model detected, using singularized version. Override with --force-plural.”

Using singularized version? What? Which model is he talking about? There are no models in my (dummy) application.

Thanks for the attention,

Fernando Brito wrote:

Why does:

*$ rails g controller project* Generates *app/controllers/project_controller.rb*

and

*$ rails g scaffold_controller project* Generates *app/controllers/projects_controller.rb* and *app/views/projects/*

This is by design. Consider:

$ rails g scaffold project name:string

You will notice an output containing something like: invoke active_record       create db/migrate/20100602201538_create_projects.rb       create app/models/project.rb       invoke test_unit       create test/unit/project_test.rb       create test/fixtures/projects.yml        route resources :projects       invoke scaffold_controller       create app/controllers/projects_controller.rb

Notice also the following line in the output:       invoke scaffold_controller

So, the scaffold_controller generator assumes the full MVC stack from model, through controller, to the views. In other words, running scaffold_controller assumes you already have a Project model and assumes the plural form that is the convention for controllers representing model objects.

$ rails g controller project

This makes no assumptions about anything and simply creates a controller file by appending _controller.rb to the name you supply to the generator.

Ah, thank you for your answer! :smiley:

I was not sure about Ruby on Rails convention of naming controllers in plural. :slight_smile: