# Newbie: Still confused on pluralizing controllers and models

**URL:** <https://www.ruby-forum.com/t/newbie-still-confused-on-pluralizing-controllers-and-models/107643>\
**Category:** Rails\
**Created:** [June 24, 2007, 6:58pm UTC](https://www.ruby-forum.com/t/newbie-still-confused-on-pluralizing-controllers-and-models/107643 "2007-06-24T18:58:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [June 24, 2007, 6:58pm UTC](https://www.ruby-forum.com/t/newbie-still-confused-on-pluralizing-controllers-and-models/107643/1 "2007-06-24T18:58:30Z")

</div>

Is there a proper pluralization practice I should be using when  
generating controlers and models?

Should it be:

script/generate controller Widget  
script/generate model Widget

or plural:

script/generate controller Widgets  
script/generate model Widgets

or maybe controllers should always be plural and the model singular?

Also, does capitalizing the first letter matter?

Thanks,  
DAN

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [June 24, 2007, 9:39pm UTC](https://www.ruby-forum.com/t/newbie-still-confused-on-pluralizing-controllers-and-models/107643/2 "2007-06-24T21:39:54Z")

</div>

Hi!

I’m no expert either, but when you generate you do it single.

It does not matter if the first word is capital but you have to do  
multiple words camelcased. So script/generate module LotsOfWiget

will make lots\_of\_wigets in your database

Whatever you type in to the name for generate model name,  
name.pluralize.underscore is called so you can test it out in the  
console if you want to see what will get created!

As far as controllers plural or singular I guess it doesn’t matter, but  
I think it makes more sense if a controller is singular since there is  
only one item. generating a controller will not get changed into a  
plural object I believe. the function underscore gets called on the  
name.

Models should always be singular.

Matt

DAN wrote:

> Is there a proper pluralization practice I should be using when  
> generating controlers and models?
> 
> Should it be:
> 
> script/generate controller Widget  
> script/generate model Widget
> 
> or plural:
> 
> script/generate controller Widgets  
> script/generate model Widgets
> 
> or maybe controllers should always be plural and the model singular?
> 
> Also, does capitalizing the first letter matter?
> 
> Thanks,  
> DAN

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [June 29, 2007, 3:39am UTC](https://www.ruby-forum.com/t/newbie-still-confused-on-pluralizing-controllers-and-models/107643/3 "2007-06-29T03:39:13Z")

</div>

On Jun 24, 2007, at 14:39 , Matt Sir wrote:

> As far as controllers plural or singular I guess it doesn’t matter,  
> but  
> I think it makes more sense if a controller is singular since there is  
> only one item. generating a controller will not get changed into a  
> plural object I believe. the function underscore gets called on the  
> name.

I believe current recommended practice is to have plural controllers.  
For example,

script/generate scaffold widget

creates app/models/widget.rb and app/controllers/  
widgets\_controller.rb What does a WidgetsController do? It controls  
all widgets (note the plural).

Michael G.  
grzm seespotcode net

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [June 29, 2007, 5:31am UTC](https://www.ruby-forum.com/t/newbie-still-confused-on-pluralizing-controllers-and-models/107643/4 "2007-06-29T05:31:29Z")

</div>

> I believe current recommended practice is to have plural controllers.  
> For example,
> 
> script/generate scaffold widget
> 
> creates app/models/widget.rb and app/controllers/  
> widgets\_controller.rb What does a WidgetsController do? It controls  
> all widgets (note the plural).
> 
> Michael G.  
> grzm seespotcode net

Here’s how I see it (one mans opinion)

DB Table =\> Plural (products, people, invoices… etc)  
Model =\> Singular (product, person, invoice… etc)  
Controler =\> Doesn’t matter. So long as you understand the connection.  
store (controller managing products)  
user\_admin (controller managing the people in your site)  
accounting (controller for invoices)

Yes granted you could pluralize your controllers, but I think since a  
controller wraps functionality around your models (its’ the CRUD after  
all) and isn’t just a series / list of models itself; making the name  
descriptive makes more sense to me.

Also, don’t forget, eventually once you get past “scaffolding-only”  
controller code your controller will be managing business logic around  
your model and not just the state of a model itself. So it will grow  
beyond the definition of “People, Invoices or Products” as a  
description.

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [June 29, 2007, 5:34am UTC](https://www.ruby-forum.com/t/newbie-still-confused-on-pluralizing-controllers-and-models/107643/5 "2007-06-29T05:34:30Z")

</div>

Jean N. wrote:

> Here’s how I see it (one mans opinion)
> 
> DB Table =\> Plural (products, people, invoices… etc)  
> Model =\> Singular (product, person, invoice… etc)  
> Controler =\> Doesn’t matter. So long as you understand the connection.  
> store (controller managing products)  
> user\_admin (controller managing the people in your site)  
> accounting (controller for invoices)
> 
> Yes granted you could pluralize your controllers, but I think since a  
> controller wraps functionality around your models (its’ the CRUD after  
> all) and isn’t just a series / list of models itself; making the name  
> descriptive makes more sense to me.
> 
> Also, don’t forget, eventually once you get past “scaffolding-only”  
> controller code your controller will be managing business logic around  
> your model and not just the state of a model itself. So it will grow  
> beyond the definition of “People, Invoices or Products” as a  
> description.

I apologise I hit enter too quick and there’s no edit on this board…

Paragraph TWO should not have “(its’ the CRUD after all)” I meant to  
correct that error and delete it before submitting.

Sorry,

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [July 14, 2007, 3:56pm UTC](https://www.ruby-forum.com/t/newbie-still-confused-on-pluralizing-controllers-and-models/107643/6 "2007-07-14T15:56:19Z")

</div>

All the code you’ve given is correct,  
unless you have “ActiveRecord::Base.pluralize\_table\_names = false” in  
you environment.rb file.

if you’re getting a load failure, I image there’s a different problem.

Go into ruby script/console  
and type “ProjectType”

hopefully it’ll give you a more verbose error,

could be that ActiveRecord::Base isn’t working properly.

> /app/models/project\_type.rb \<== should that be ProjectType.rb,  
> projectType.rb or as is?  
> class ProjectType \< ActiveRecord::Base  
> end
> 
> /db/migrate/008\_create\_project\_types.rb \<== created using generate  
> model projectTypes IIRC  
> class CreateProjectTypes \< ActiveRecord::Migration  
> def self.up  
> create\_table :project\_types do |t|  
> t.column “name”, :string  
> end  
> end
> 
> /app/controllers/project\_types\_controller.rb  
> class ProjectTypesController \< ApplicationController  
> scaffold :project\_types  
> end
> 
> all this (begun using script/generate commands, then for better or  
> worse edited by me to try getting around load errors) results in:  
> LoadError in Project typesController#index
> 
> app/models/project\_type.rb to define ProjectType

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [July 13, 2007, 11:24pm UTC](https://www.ruby-forum.com/t/newbie-still-confused-on-pluralizing-controllers-and-models/107643/7 "2007-07-13T23:24:52Z")

</div>

I think I got all twisted around with camels and pluralizes, such  
that I’m getting load errors. This is just a small identity  
attribute that I want to be able to add to, so having auto-generated  
scaffold is okay for now… once I get past load errors!

/app/models/project\_type.rb \<== should that be ProjectType.rb,  
projectType.rb or as is?  
class ProjectType \< ActiveRecord::Base  
end

/db/migrate/008\_create\_project\_types.rb \<== created using generate  
model projectTypes IIRC  
class CreateProjectTypes \< ActiveRecord::Migration  
def self.up  
create\_table :project\_types do |t|  
t.column “name”, :string  
end  
end

/app/controllers/project\_types\_controller.rb  
class ProjectTypesController \< ApplicationController  
scaffold :project\_types  
end

all this (begun using script/generate commands, then for better or  
worse edited by me to try getting around load errors) results in:  
LoadError in Project typesController#index

app/models/project\_type.rb to define ProjectType
