Is it the rails way to use singular or plural controller names?
Should I use /article or /articles开发者_StackOverflow社区 ?
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'
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
.
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
精彩评论