15Jul
Compromising with Rails: The Inflector and the Plural of “series”
Posted by Elf Sternberg as programming, ruby
I was working today on my storyengine / storykeeper / narrator codebase when I hit a snag. Storyengine converts text to XML and embeds in into a database. Storykeeper is a little rails program that I use to make sure all my keywords and so forth are set up correctly. And narrator is le grand engine; whenever you read a story from my website, it’s been pulled out of the database by narrator.
This code has been undergoing a bit of a rehash over the past month, and I slammed into a headache. ActiveRecord doesn’t like the word “series.” I liked the word series and didn’t want to give it up; it describes the whole of a work. Rails depends upon distinguishing between the singular and the plural of something, and the plural of series is, uh, “series.”
I tried “set” instead, thinking it a poor second, but then the SQL engine died, telling me that set was a reserved word. I finally settled on “serial” for the singular and “series” for the plural, but that meant I had to argue with the inflector, which meant that after active_record was loaded with require, I had to:
Inflector.inflections do |inflect| inflect.irregular 'serial', 'series' end
And everything almost worked There was one inflection that didn’t, which was very odd. (This is Rails 2.0.2). But it was kind-of annoying that this little compromise wasn’t available from the beginning.
- Tags: activerecord, pluralization, rails, ruby
2 Responses to Compromising with Rails: The Inflector and the Plural of “series”
Paul
February 11th, 2010 at 12:26 pm
So this is the approach you settled on? I’m in the exact same boat…building an app for adventure racing…and I need a “series” model.
Elf Sternberg
February 11th, 2010 at 12:33 pm
Well, as I said in the original, I went with “serial” for singular and “series” for plural.
But what I really did was switch to Django and accept the “_set” suffix for lists of objects.