Blankman
Blankman

Reputation: 266910

Is it the rails way to use singular or plural controller names?

Should I use /article or /articles ?

Upvotes: 18

Views: 14247

Answers (3)

Vinay
Vinay

Reputation: 41

You can use either. However, It is better to use the plural. A controller is a class that, most often, accesses more than one instance of a model.

Eg: For a model by the name Subject, a controller accesses lot of instances of Subject, viz., subjects. Therefore, we name SubjectsController instead of SubjectController.

Upvotes: 4

madlep
madlep

Reputation: 49656

Plural

For the name of the actual controller class, and file it lives in. e.g class ArticlesController... living in /app/controllers/articles_controller.rb

Upvotes: 2

Pan Thomakos
Pan Thomakos

Reputation: 34340

You can use either. If you are defining your routes using resource(s) then it's best to use plural controller names, because that is the default:

resources :articles
resource :articles

But it is possible to specify other controller names as well:

resources :articles, :controller => 'article'
resource :article, :controller => 'article'

Upvotes: 35

Related Questions