This project is archived and is in readonly mode.
Autocorrect plural ModelName passed to script/generate scaffold
-
Ryan McGeary
+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 modelandscript/generate resourcetoo. -
Coderifous
+1
-
Pratik
- 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.
Thanks.
-
Pat George
Pratik,
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".
Pat
-
Ryan McGeary
Pratik,
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
Hey,
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.
Thanks.
-
Ryan McGeary
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
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
Hmm lol :)
-
Michael Trim
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
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.
-
Pratik
- State changed from incomplete to open
-
Repository
- 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