This project is archived and is in readonly mode.
Strange pluralize and routing
Reported by Sergey Kish | February 22nd, 2009 @ 09:26 PM | in 2.x
Steps to reproduce:
$ rails test
$ cd test
$ ./script/generate scaffold tax
$ rake db:migrate
Target browser to /taxes/, Get
undefined local variable or method
new_tax_path'
Lets see routes
$ rake routes
taxes GET /taxes
formatted_taxes GET /taxes.:format
POST /taxes
POST /taxes.:format
new_taxis GET /taxes/new
formatted_new_taxis GET /taxes/new.:format
edit_taxis GET /taxes/:id/edit
formatted_edit_taxis GET /taxes/:id/edit.:format
taxis GET /taxes/:id
formatted_taxis GET /taxes/:id.:format
PUT /taxes/:id
PUT /taxes/:id.:format
DELETE /taxes/:id
DELETE /taxes/:id.:format
/:controller/:action/:id
/:controller/:action/:id.:format
Its strange pluralize...
Next I've tryed to replace links to taxis. But <%= link_to 'Back', taxis_path %> called from /taxes/1 return /taxes/1
Comments and changes to this ticket
-
Sergey Kish February 22nd, 2009 @ 09:31 PM
- 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 February 22nd, 2009 @ 09:33 PM
- 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 March 8th, 2009 @ 12:05 PM
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 March 8th, 2009 @ 12:37 PM
- 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 March 8th, 2009 @ 03:57 PM
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 versi
on. 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 end
Maybe add note too?
For example
if @name != @name.pluralize.singularize logger.warning "Attention you will get troubles this such name. Get another please." end
Or even
if @name != @name.pluralize.singularize logger.warning "\033[01;31mAttention you will get troubles this such name. Get another please.\033[00m" end
I've attached the diff to generators file.
-
CancelProfileIsBroken March 8th, 2009 @ 04:03 PM
- State changed from wontfix to open
Seems a reasonable suggestion, as several people have hit this.
-
Sam Ruby April 15th, 2009 @ 02:47 PM
I just hit this too. In addition to the warning, I'd suggest adding "tax" to the list of irregular inflections.
-
Rishav Rastogi April 11th, 2010 @ 11:29 PM
- 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.
-
Santiago Pastorino April 12th, 2010 @ 12:56 AM
- 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 April 12th, 2010 @ 01:04 AM
So what about #2399 and "Rails has a longstanding policy of not taking further inflector patches. Use an initializer in your application instead"?
-
Ryan Bigg April 12th, 2010 @ 01:09 AM
Santiago, why does inflection3 comment out a line? Also, could you please provide tests with your patches? Thanks.
-
Santiago Pastorino April 12th, 2010 @ 01:25 AM
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 April 12th, 2010 @ 01:25 AM
- no changes were found...
-
Santiago Pastorino April 12th, 2010 @ 01:59 AM
- 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 -
Ryan Bigg October 9th, 2010 @ 09:47 PM
- Tag cleared.
- Importance changed from to Low
Automatic cleanup of spam.
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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 1800 Resources Routing ending in 'base' You can workaround by setting up your own inflections. #2...
- 2212 Make polymorphic_url more consistent with routing code Applying this patch is a prerequisite to getting a good f...
- 1747 the word "kasse" seems to be a reserved word ?! Dupe of #2046