Header left Header right
 

An Amusing Rails Bug

Published: March 12th, 2008

I just went through something rather amusing, and I sort of feel bad for not wanting to fix this… so here’s the story.

The Story

I started off with a typical Rails work day, and since it’s a new project I’m doing a lot of scaffolding to get my files set up. One of the models that I was creating was an “analysis” model. I was of course curious if this would pluralize properly, so I fired up my “script/console” typed in “‘analysis’.pluralize” and out came “analyses”, perfect! This means that the script/generate rspec_haml_scaffold1 should work, and guess what? It did… for the most part. When I added the required fields in my migration, then tried to migrate up, guess what happened? “uninitialized constant CreateAnalyses” that’s what. I scratched my head and went “well, something has to be wrong in the migration…”. Guess what I found?

Laughter

Did you guess properly? If you didn’t, well here’s the reason I started laughing uncontrollably like an immature first grade student:

  class CreateAnalyAses < ActiveRecord::Migration

Yes, you read that right, “class”, “Create…”, “AnalyAses”. This may or may not be funny to you, but it was damn funny to me.

The Problem

What stumps me more than anything, is how the heck did this happen? I looked at the generation template code and I see “name.classify.pluralize”, that should spit out “Analysis” just like our script/console pluralize test (all classify does is Camelize).

Also something to note is that every other file used the proper inflections, it’s only the migration that screwed up.

Does anyone have an answer? Did anyone else laugh at this? And lastly, will anyone submit a patch? I almost hope someone doesn’t.

Hopefully the answer to this isn’t so obvious and I won’t feel like a dunce for stumbling into this.

  1. A sweet plugin that CitrusByte released for Haml RSpec Scaffolds : http://blog.citrusbyte.com/2008/3/11/what-s-that-rspec-haml-scaffolds-yes-it-is []
Enter your comment

Ready. Set. Go.

In terms of the formatting, you're allowed to use markdown, textile, or basic html; it's truly up to you -- what strikes your fancy?

You don't have to worry about your e-mail address being sold to a russian-spam-mafia. I'm only going to use it for my own weird needs; like asking you out for a date on a lonely night of coding.