[Rails] Pluralization Confusion(s)

John Wilger johnwilger at gmail.com
Tue Feb 1 14:17:55 GMT 2005


On Mon, 31 Jan 2005 22:48:26 -0500, Alexander Payne <al3x at al3x.net> wrote:
> "For the time being, which usage is more common for naming controllers
> and models?  Do you like to put the object being operated on in singular
> or plural?"
 
> In looking through other people's Rails applications I see that models
> are consistently in the singular (which makes good sense), but I've
> seen controllers and their corresponding views in both the singular and
> plural.  Which is to say I've seen both:

> Is one correct?  Is the pluralization that `script/generate scaffold
> Post` decides on correct?  An authoritative answer, please!

I think that the mistake many people are making is tying the idea of
the controller too closely to the idea of the model. A controller
should simply be named sensibly according to what it _does_. If your
controller is simply a CRUD interface for a single type of model, then
it probably makes sense to use a pluralized version of the model name
in the controller; but in more complex scenarios this doesn't
necessarily hold. For instance, if I'm creating an ecommerce site, I
might have one controller that outputs the "catalog" portion of the
site. This would deal with several different model objects such as
Product, Category, Review, etc. While you _could_ create a seperate
controller for each of these, I like to put the whole "catalog" in one
CatalogController. Basically, keep similar ideas in one place based on
what types of operations the _user_ is performing.

That's just my 2 cents, though.

-- 
Regards,
John Wilger

-----------
Alice came to a fork in the road. "Which road do I take?" she asked.
"Where do you want to go?" responded the Cheshire cat.
"I don't know," Alice answered.
"Then," said the cat, "it doesn't matter."
- Lewis Carrol, Alice in Wonderland


More information about the Rails mailing list