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
  • 23,615
  • 19
  • 137
  • 163
max pleaner
  • 25,009
  • 9
  • 61
  • 111

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,030
  • 4
  • 42
  • 79
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,392
  • 3
  • 29
  • 46
1

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

dphaener
  • 130
  • 1
  • 7
  • 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