Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Should I use /article or /articles ?

like image 503
Blankman Avatar asked Feb 25 '11 00:02

Blankman


People also ask

Should Rails controllers be plural?

The Controller suffix is always singular. The name of the resource is usually plural. Controller actions use snake_case and usually match the standard route names Rails defines ( index , show , new , create , edit , update , delete ).

Should controllers be plural or singular?

Controller names are either singular or plural : Using “rails g resource” names the controllers plural, which makes sense because I think about them controlling many routes. Resource names are singular : They create a lot of mvc framework, the name you pass will become the model name, and let rails pluralize the rest.


1 Answers

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'
like image 73
Pan Thomakos Avatar answered Sep 20 '22 07:09

Pan Thomakos