Skip to Content »

Michi’s blog » Pluralization in Rails

 Pluralization in Rails

  • December 9th, 2007
  • 10:13 pm

So, there is this one big and neat framework called Rails, building on top of this one neat new programming language called Ruby.

And one of the things that makes Rails so Damn Neat is that if you only set things up the right way around, it guesses almost everything you need it to guess for you.

One of the ways it does this is by pluralization. Basically, the model Foo has a model defined in app/model/foo.rb and it accesses the database table foos.

So, when talking a good friend through the basics, we created the table persons and generated the model Person. And promptly got an error from the framework.

It turns out that the pluralization of person is people. I wonder what else irregularities they built into the system. If I have a model called Index, does Rails expect it to read from the database table indexes or from indices?

Edited to add:

So, I found out that in the Rails console, I can fiddle around with pluralization myself.

Which lead to this experiment

>> "index".pluralize
=> "indices"
>> "simplex".pluralize
=> "simplices"
>> "matrix".pluralize
=> "matrices"
>> "complex".pluralize
=> "complices"

And at this point, the chosen pluralization engine simply Does Not Work. The pluralization of complex, at least as used in mathematics, is under no circumstances complices. We’d say complexes. Matrices, on the other hand, pluralizes correctly. And simplices pluralize correctly or incorrectly depending on which mathematician you ask.

13 People had this to say...

  • ray
  • December 9th, 2007
  • 23:40

this is the kind of thing that probably seemed really neat to the designers while they were designing it, but turns out not to be so neat in practice. these sorts of “features” hardly ever go away, it seems..

  • Michi
  • December 10th, 2007
  • 0:10

It sounds like a really neat idea.

Until you realize that pluralization is actually not quite as regular in English as it is in Japanese.

And that a coder needs to frigging GUESS which words get pluralized regularly, and which words the original coder really knew how to form.

Easier if they just did “append an s” with some simple variation on the theme. I’m ready to swallow “append es when ends in a sibilant” if they REALLY want to.

  • Chris
  • December 10th, 2007
  • 0:22

Answer: indices.

But the way to do it is to create at least the model and a rakefile with which to create the database table all at once by typing a script/generate command. You can also create a controller and views, and a host of other things, depending on which of the following commands you use (these are some of the Rails 2.0 options):

script/generate model index
script/generate resource index
script/generate scaffold index

Rails isn’t about guessing pluralizations – it’s more about creating the correct pluralizations for you.

If you’re creating a DB table and then created a model, you’re not really using Rails the way it was designed to be used.

Also, the person/people thing you find so distasteful is a feature of Ruby, not of Rails. It wasn’t an irregularity built into the system. Most Rails developers think it’s great, though, as it leads to meaningful URLs which can be read better by humans. If you have a problem with this, you’d better keep away from Ruby, never mind Rails!

I take your point, but are you sure you’ve studied Rails enough to dismiss it like this? I’m sure Haskell could be dismissed just as lightly by a novice, and that would be equally unfair.

  • Michi
  • December 10th, 2007
  • 0:34

Chris: If you take what I write as dismissal, then you’re reading way too much into this. I am swept away by Rails. I find it Cool and Funky and Everything I Have Ever Wanted For All My Web Projects.

And then, there are annoyances. And quirks. Many of which are glossed over by tutorials and blog entries that prefer to write Yet Another Cookbook instead – a bit like the Haskellite monad tutorial craze. And I find the readability push great, and nice, and makes for good code.

It’s just .. nothing nowhere told me about generate resource. Nothing nowhere told me about producing database designs with the generate script. And once I have a design of the model I want, the actual implementation can be as small as 2 lines; with ALL the magic happening in the choice of names for the database tables and columns.

So, I create the database tables secure in knowing that once I dive into the controller, the model will just hand me everything I need Just Like That.

Which is GREAT.

If only somewhere someone would tell me all the conventions I need to follow, instead of me picking them out of all the error messages I’m generating.

  • Chris
  • December 10th, 2007
  • 0:55

Apologies – I thought you were being sarcastic. Yes, the lack of documentation is infuriating.

When it comes to code generation, you can type:

ruby script/generate

to see the command options, then e.g.

ruby script/generate scaffold

to see what the scaffold command does. In fact, “script/generate scaffold” is particularly helpful, but you’ll have to be up on the new RESTful way of doing things.

The creator of Rails makes no bones about the fact that Rails is opinionated and that you have to do things the Rails way. That’s great, but could also surely be its downfall one day, as it’ll surely lead to stagnation.

The new book on Rails by Obie Fernandez is a great overview of the fundamentals of Rails 2.0. Kind of silly that the documentation on its own isn’t enough, though.

BTW, I hope something as noob-friendly will come along for Haskell one day. Learn sexy web framework vs. learn monads? You can kind of see why it’s Ruby, not Haskell, that is in the ascendant right now :-)

  • Michi
  • December 10th, 2007
  • 10:39

Chris: And I for one don’t care THAT much about the general public’s opinion of noob-friendliness when it comes to Haskell. In fact, the reason I got pulled into Haskelland is precisely some of the features people struggle the most with.

Categories are cool. Categorified logic is really cool. And a programming language and community where category theory is The Way Things Get Done – I’m sold.

Also, there’s no way I’ll end up getting a mathematics paper published that’s written in RoR. I am, though, with a bit of luck and good reviews, getting a paper out sometime next year written in Haskell.

  • Chris
  • December 11th, 2007
  • 4:10

>> And at this point, the chosen pluralization engine simply Does Not Work.

I’m not all that experienced, and even I would have no problem overriding that in Rails. If you’re not sure how, try asking in the Rails Google group. But you’re obviously looking for problems, so you should probably avoid Rails and code your sites in Haskell so that you don’t waste your time on something as vulgarly popular as Rails with its out-of-control pluralizations and all :-p.

BTW, the more arrogance I come across in the Haskell coimmunity, the less I want to carry on learning it. But then again, you “don’t care THAT much about the general public’s opinion of noob-friendliness when it comes to Haskell,” so there’s probably little point in telling you this!

  • Leadhyena
  • December 11th, 2007
  • 7:25

I have complained about this pluralization thing in Rails for a long time now. Pluralization in a living language is simply too much of a moving target; what happens when they change the plural of a word such as “virus” from the currently correct “viruses” to “virii” as per the common usage? Does that mean that current Rails code will break upon an upgrade unless there’s a database refactoring that will bound to break other things? In addition it should be some decidable and short mechanical rule. Why not BagOfVirus? Maybe ColPeople? What happens when I want a database of relatives with the Bags surname? Is it Bagss or Bagses? Neither make much sense. It’s just a bad design choice: if you depend on reflection, don’t base the naming convention on a hotly debated topic of grammar, but rather make it straightforward and mechanical.
Just my 2 cent rant…

  • Michi
  • December 11th, 2007
  • 10:10

Chris: How much of my blog have you seen so far? Did you even notice that I tend to write mostly about the dark and ugly corners of research-level algebra, interspersed with me writing about the latest Cool Programming Thingie I’ve run across?

I already said in the discussion here that I find Ruby on Rails a REALLY DAMNED GOOD web programming framework, and that I’m quite happily learning how to use it. This blog post is to point at one of the properties of the framework that I personally find misguided, in that it settles one particular grammatical description of the English language as the one being used for a programming convention, and that in doing that stumbles across quite a few things that are no longer actual properties of the language described, but rather a more or less arbitrarily chosen subset of the rules describing the language.

My example with the x -> ces words is there in order to point out that the rules implemented simply do not correspond to the natural language usage. We don’t say complices. We do say matrices, however, and whether we do say simplexes or simplices is controversial enough that my spell checker doesn’t recognize simplices and that I have been asked by editors to change the word into simplexes on occasion.

Leadhyena’s example with viruses contra virii is also quite relevant.

Sure, I can configure Rails not to use pluralization. I can extend the pluralization engine to accommodate my own expectations. But isn’t this running contrary to the idea of having a web framework with readable code as the non-plus-ultra?

  • Michi
  • December 11th, 2007
  • 10:19

Leadhyena: Another issue here is the we you refer to. The English language doesn’t have an authoritative language defining body – the OED works by description and not prescription.


The proper plural of “virus” will never be “virii”, since that’s the plural of the (nonexistent) “virius”. The word “virus” has no Latinate plural, and its adaptation to an English noun “virus” then takes a standard English plural: “viruses”.

Nobody learns their damned Latin anymore.


I was just reading about this issue on Reddit, started thinking about how one would implement it in Haskell, decided to Google to see if such a thing existed, and came across your blog :-)

FWIW, it looks like the Rails guys’ real error was writing a half-arsed inflector of their own, rather than porting Damien Conway’s Lingua::EN::Inflect. But that’s based on a cursory scan of them both.

So anyway, here’s my question: which would be more idiomatic Haskell,

newtype Singular = String
newtype Plural = String

inflect :: Singular -> Plural

or just

inflect :: String -> String


Want your say?

* Required fields. Your e-mail address will not be published on this site

You can use the following XHTML tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>