This project is archived and is in readonly mode.
Strange pluralize and routing
-
Sergey Kish
- Title changed from Strange pluralize and routing to prevent if can't fix
If bug cannot be fixed (or you think it is not bug) maybe add warning to ./generate/controller?
-
Sergey Kish
- Title changed from prevent if can't fix to Strange pluralize and routing
Sorry it has changed the title, I want only comment title.
-
CancelProfileIsBroken
Still a problem in RC2, though the routes have changed a bit:
Phoenix ~/scratch/depot $ rake routes (in /Users/mike/scratch/depot) taxes GET /taxes(.:format) {:action=>"index", :controller=>"taxes"} POST /taxes(.:format) {:action=>"create", :controller=>"taxes"} new_taxis GET /taxes/new(.:format) {:action=>"new", :controller=>"taxes"} edit_taxis GET /taxes/:id/edit(.:format) {:action=>"edit", :controller=>"taxes"} taxis GET /taxes/:id(.:format) {:action=>"show", :controller=>"taxes"} PUT /taxes/:id(.:format) {:action=>"update", :controller=>"taxes"} DELETE /taxes/:id(.:format) {:action=>"destroy", :controller=>"taxes"} /:controller/:action/:id /:controller/:action/:id(.:format)The underlying issue is:
"tax".pluralize.singularize => "taxis"
The generator uses the original singular name fed in when building views and controllers. But the routing code initializes the singular name by singularizing the name in the map.resources call. Hence the mismatch.
-
CancelProfileIsBroken
- State changed from new to wontfix
Changing this behavior would require a major upheaval in the source, and you can get the right routes by supplying your own custom inflectors to handle "tax" <=> "taxes".
-
Sergey Kish
There is even simple decision - use another name. But at first I need to know that will have troubles with current choice.
Rails already show a note on using singularized name $ ./script/generate scaffold prices test:string
warning Plural version of the model detected, using singularized version. Override with --force-plural.
It is few lines in /lib/rails_generator/generators/components/scaffold/scaffold_generator.rb
def initialize(runtime_args, runtime_options = {})
super if @name == @name.pluralize && !options[:force_plural] logger.warning "Plural version of the model detected, using singularized version. Override with --force-plural." @name = @name.singularize endMaybe add note too?
For example
if @name != @name.pluralize.singularize logger.warning "Attention you will get troubles this such name. Get another please." endOr even
if @name != @name.pluralize.singularize logger.warning "\033[01;31mAttention you will get troubles this such name. Get another please.\033[00m" endI've attached the diff to generators file.
-
CancelProfileIsBroken
- State changed from wontfix to open
Seems a reasonable suggestion, as several people have hit this.
-
Sam Ruby
I just hit this too. In addition to the warning, I'd suggest adding "tax" to the list of irregular inflections.
-
Rishav Rastogi
- Assigned user set to Ryan Bigg
Tax => Taxes works fine in 2.3.5.
But I noticed, that there is no warning when using plural names for models though
./script/generate model prices
No longer throws any warnings.
-
Ryan Bigg
I can duplicate this on 2.3.5. Rishav, how did you test this?
-
Ryan Bigg
Here's a patch to fix this.
-
Santiago Pastorino
- Tag changed from routing error, pluralize, routing to routing error, 2.3.x, 3.0.0.beta, patch, pluralize, routing
- Assigned user changed from Ryan Bigg to Jeremy Kemper
I'm with Sam Ruby so patches provided to 2-3-stable and master
-
Yaroslav Markin
So what about #2399 Incorrect inflectors for 'business' or '*ness' and "Rails has a longstanding policy of not taking further inflector patches. Use an initializer in your application instead"?
-
Ryan Bigg
Santiago, why does inflection3 comment out a line? Also, could you please provide tests with your patches? Thanks.
-
Santiago Pastorino
Yes you're right Ryan i was trying things and forgot to uncomment this line also i was a bit lazy and did things wrong, ;).
Uploading again. -
Santiago Pastorino
- State changed from open to wontfix
Santiago Pastorino: why we don't fix inflection issues?
David Heinemeier Hansson:
1) because there are many, many more unlikely-to-be-used irregular inflections that we'd then have to do
2) because changing some of the existing rules might break applications that depend on the old behavior
3) because it's so easy to add your own inflections
