Repository navigation
Conversation
Resources_controller defined an internal controller method called 'request_path'. If you've got a 'map.resources :requests' in your routes.rb file, that defines a named route called 'request_path'. When these two meet... wackiness ensues! To avoid the wackiness (which manifests as complaints from the code that implements the named route), this patch renames the 'request_path' method, and its companion 'nested_request_path', so that they're no longer at risk of being trampled by eccentric named routes.
|
Superseded by #19, which is a rebase of this idea onto the current code — thank you for diagnosing this, Robert: you were right, and it has gone unnoticed since 2010. For the record, the collision is still live on master today (Ruby 4.0.7 / Rails 8.1.4): #19 does the same rename you proposed, with the name One behavioural note carried into the CHANGELOG: I'll close this as superseded once #19 is merged — the credit for finding it is in the commit message, the PR description and the 5.0.1 CHANGELOG entry. |
Fix request_path being replaced by a named route helper (supersedes #3)
A route like `resources :requests` generates a public `request_path` helper, and Rails includes the url_helpers module into controllers after resources_controller's modules (url_helpers sits at ancestor index 7, RequestPathIntrospection at 12, and the lower index wins). resources_controller's own request_path was therefore replaced by the route helper, so it read the helper's value instead of the path of the current request, and could not work out the enclosing resources: with a top level `resources :requests` route in the spec app, 6 examples in spec/lib/request_path_introspection_spec.rb fail. The internal reader is renamed to rc_request_path, so that no plausible route name can collide with it, and the specs are updated to match. Based on PR ianwhite#3 by Robert Thau, which diagnosed this and proposed the same rename (as path_of_request) but is written against the pre-rename lib/ardes/ layout and RSpec 2 syntax, so it no longer applies. Adds a regression spec that includes a module defining a public request_path into the controller under test - the position url_helpers occupies - and asserts the path of the request is still read. Co-authored-by: DeepSeek <agent@deepseek.com>
Updating my app, I discovered that 'map.resources :requests' breaks recent
versions of resources_controller --- this defines a 'request_path' named route,
which in turn winds up clobbering resources_controller's internal method by
that name.
This is a patch to deal with the issue, by renaming the method to
'path_of_request', which takes it out of the line of fire. Most of it is
updating the specs (which all still pass... at least after a 'mkdir tmp'
so it could create the sqlite3 test db).
FWIW, this is currently lighthouse ticket #9:
http://ianwhite.lighthouseapp.com/projects/10598/tickets/9-request_path-method-gets-clobbered-by-named-routes