This project is archived and is in readonly mode.

#333 ✓resolved
Pat George

Autocorrect plural ModelName passed to script/generate scaffold

Reported by Pat George | June 4th, 2008 @ 10:28 PM

During his RailsConf '08 keynote Jeremy Kemper accidentally illustrated a common problem users run into when using "script/generate scaffold" - passing in the pluralized ModelName causes issues. The user must destroy the scaffold and regenerate it using the singularized form.

This simple patch recognizes when a user has given a plural ModelName, warns the user, and then uses the singularized form of that ModelName to generate the scaffold.

It can be overridden using the switch "--force-plural".

Patch adds a new switch option and an if stmt to ScaffoldGenerator and tests.

Comments and changes to this ticket

  • Ryan McGeary

    Ryan McGeary June 5th, 2008 @ 02:27 AM

    +1 Tested and inspected. I like the auto-correcting nature as to not require remembering whether a singular or plural is required. I'd love to see this added to script/generate model and script/generate resource too.

  • Coderifous
  • Pratik

    Pratik June 5th, 2008 @ 10:25 PM

    • State changed from “new” to “incomplete”
    • Assigned user set to “Pratik”

    If someone tries to pass pluralized name to generator, they should be given three choices on command line to contrinue :

    • Continue generating with plural
    • Singularize it
    • Abort

    This will also get rid of --force-plural option.


  • Pat George

    Pat George June 6th, 2008 @ 02:46 PM


    The only other place I found in which a prompt is used in generation - Rails::Generator::Commands::Create.file - can be overridden by the --force and --skip switches. Which means to stick with the precedent I'd still need to use a switch (or multiple switches) to override the prompt.

    So if you're sure you want a prompt how about the default would be "ask" with optional switches of "--use-plural" and "--use-singular". Although, IMO, the default should be "use-singular".


  • Ryan McGeary

    Ryan McGeary June 6th, 2008 @ 03:45 PM


    I agree with Pat. Passing a plural to a scaffold generation is almost always a mistake, so why not just get out of the way and auto-correct it? After all, if you do decide to override the scaffold generation with a plural, the generated scaffolding will actually result in NameErrors while accessing the named resource routes. Let's continue to enforce good Rails conventions while also having niceties that auto-correct a common human error.

    I don't see a prompt asking whether you want to pluralize or abort as adding a lot of benefit, especially considering you can always script/destroy your way out of a mistake. Was the idea for a prompt just a way to avoid the --force-plural option or was there a different underlying benefit that I'm not thinking of? Thanks for your time on this.

  • Pratik

    Pratik June 6th, 2008 @ 03:55 PM


    I feel if Rails auto corrects the mistake, people would possibly keep repeating the same mistake. If we add an extra step for people making mistakes, it's more likely they'll take a notice and not do it again.

    Having said that, if prompting user involves a lot of extra efforts on code front, we can just go with what you already have.


  • Ryan McGeary

    Ryan McGeary June 6th, 2008 @ 04:17 PM

    Cool. Pat's patch does display a warning message. I realize this isn't as painful as a halting prompt, but I'm one of those that can't stand seeing warnings, so it serves as enough of a wrist slap for me.

    $ script/generate scaffold books
         warning  Plural version of the model detected, using singularized version.  Override with --force-plural.
  • Pat George

    Pat George June 6th, 2008 @ 04:26 PM

    I think prompting the user involves more effort than it's worth on the code front.

    I do see your point but I think Jeremy's accidental example made it clear that it's not really a teaching tool that's needed but more a nudge in the right direction.

  • Jeremy Kemper
  • Michael Trim

    Michael Trim June 6th, 2008 @ 11:24 PM

    This probably deserves a separate ticket, but what about 'uncountable' names e.g. "news" (where "news".singularize == "news".pluralize == "news")? This works fine except that the named routes clash so have to be overridden with e.g. :singular => 'news_item' in the routes and renaming all the references in the generated files. It would be nice if the generator detected this as well.

  • Pat George

    Pat George June 7th, 2008 @ 01:02 AM

    Assuming we come to an agreed upon solution and I get the 3 +1s necessary, I'll be looking into Ryan's suggestion next (to put the auto correction code into other Generators).

    When that happens, I would be interested in looking into the handling of uncountables. But yes, it should be a separate ticket.

  • Christopher Murphy
  • Pratik

    Pratik June 12th, 2008 @ 04:24 PM

    • State changed from “incomplete” to “open”
  • Repository

    Repository June 27th, 2008 @ 04:42 PM

    • State changed from “open” to “resolved”
    • Tag set to generators, patch, railties

    (from [4ddca325eeef46e640a225efb9b297260e1e8e7d]) Warn and uses singularized ModelName if a plural ModelName is given to script/generate. Override with --force-plural. [#333 state:resolved]

    Signed-off-by: Pratik Naik

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>