4

If i am generating a controller, should I make the controller name plural?

For example, I am generating a "central" controller to be the root directory (index) of the site. Is it fine to do "rails g controller central"?

I am getting mixed messages from visiting various websites.

It doesn't make that much sense to pluralize it, but I don't want to mess with Rails internal functioning.

Jon Schneider
  • 25,758
  • 23
  • 142
  • 170
max pleaner
  • 26,189
  • 9
  • 66
  • 118

3 Answers3

2

I don't think it should always be plural. It's convenient to pluralize only when the controller is associated with a model.

The rails generate guide itself gives an example of a CreditCard controller that is not pluralized. I don't think the rails guides would give a wrong example.

Tamer Shlash
  • 9,314
  • 5
  • 44
  • 82
1

rails g controller central will give you CentralController.

The "mixed messages" comes from less-than-perfect domain analysis, where each controller controls one list of model objects. class PostsController presents a list of class Post, objects, for example. Often the better analyses introduces a DIFFERENT name into the system. Such as a class BlogController that controls a list of class Post model objects.

Phlip
  • 5,253
  • 5
  • 32
  • 48
1

I believe the convention is to pluralize the controller name, and the corresponding model is singular.

dphaener
  • 140
  • 1
  • 8
  • that's what I ... raled against. In MVC-land, a controller should generally _not_ have a "corresponding model". Otherwise (disregarding the actual Rails plumbing), you really just have one domain-concept split in two. – Phlip Nov 15 '13 at 23:16