This project is archived and is in readonly mode.
nested resource routes not generated correctly (rails 2.3)
Reported by Ian White | September 14th, 2009 @ 01:23 PM | in 2.3.6
In rails 2.3 nested resource routes are not generated correctly. In particular, nestings show up as query params instead of nesting path segments.
This behaviour is not present in 2.2 and earlier.
Example:
config/routes.rb:
map.resources :posts
map.resources :authors, :has_many => :posts
In a Rails 2.3 console (incorrect behaviour):
>> include ActionController::UrlWriter
>>
>> url_for :controller => 'posts', :action => 'index', :author_id => '1', :only_path => true
=> "/posts?author_id=1"
In a rails 2.2 console (the correct behaviour):
>> include ActionController::UrlWriter
>>
>> url_for :controller => 'posts', :action => 'index', :author_id => '1', :only_path => true
=> "/authors/1/posts"
If the map.resources :posts
line is removed from
the routes file, then the correct result is returned. This leads me
to believe that this is something to do with the algorithm that
maps params to routes. Has this changed in 2.2. > 2.3? (Just
looking for a place to start debugging)
Comments and changes to this ticket
-
Sam Ruby September 17th, 2009 @ 04:55 PM
I've verified that this happens in Rails 2.3.4, but not in Rails 2.3.3.
-
Tom Stuart September 17th, 2009 @ 05:05 PM
Yeah, this is broken.
FWIW you can turn on the old routing behaviour by commenting out the
ActionController::Routing.generate_best_match = false
line in config/initializers/new_rails_defaults.rb, which Josh introduced in commit 6fdfe4cb5fa85160f5d91bad64d5c23b4f87f820.
-
Michael Koziarski September 17th, 2009 @ 10:12 PM
- Milestone set to 2.3.6
- Assigned user set to josh
Josh,
this is all you
-
josh September 18th, 2009 @ 03:49 AM
- State changed from new to open
@Ian does using the 2.x generation behavior fix this issue? Or is it present in both cases?
-
Tom Stuart September 18th, 2009 @ 06:51 AM
Yes, using the 2.x generation behaviour (
ActionController::Routing.generate_best_match = true
) fixes the problem. -
Ian White September 18th, 2009 @ 08:32 AM
@Josh, as Tom says, using
generate_best_match
fixes it. As does flipping the order of the route declaration.Is this expected Rails 3 behaviour?
-
josh September 18th, 2009 @ 03:19 PM
- State changed from open to invalid
Correct.
"ActionController::Routing.generate_best_match = false" is the default option for new projects since it is going to be the only option in Rails 3.
-
Tom Stuart September 18th, 2009 @ 03:22 PM
Which is why this ticket is valid: the breakage occurs when
ActionController::Routing.generate_best_match = false
. -
Tom Stuart September 18th, 2009 @ 03:33 PM
Oh, I see, it's actually meant to work like this. Never mind.
-
Sam Ruby September 18th, 2009 @ 06:51 PM
But Rails 3.0 does not behave this way.
http://intertwingly.net/projects/AWDwR3/checkdepot-2.3.3.html
http://intertwingly.net/projects/AWDwR3/checkdepot-2.3.4.html
http://intertwingly.net/projects/AWDwR3/checkdepot.htmlhttps://rails.lighthouseapp.com/projects/8994/tickets/3224-234-rout...
[ at the moment, 3.0 has an unrelated failure, which is documented here: https://rails.lighthouseapp.com/projects/8994/tickets/3214-transact... ]
-
josh September 18th, 2009 @ 07:09 PM
@Sam, this patch has not been applied to master since the current router will be completely rewritten. The motivation for this switch in 2.x is to easy the pain of upgrading to the new router. Rails 3.0 will not have this flag. All routes will be generated identical to the "ActionController::Routing.generate_best_match = false" behavior.
I'm still in the progress of integrating the new router into master. I expect a few more weeks of work are left.
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
Tags
Referenced by
- 3224 2.3.4 routes regression Possibly a dupe of #3198
- 3224 2.3.4 routes regression Agreed. I've verified that #3198 happens in 2.3.4 but not...
- 3224 2.3.4 routes regression Expected behavior - see discussion on #3198.
- 5700 url_for produces wrong URL for nested resources (also "order" in searchlogic) It looks similar to ticket #3198, but the caller context/...