I need to determine the number of route segment keys in the current path for an application I'm working on, and despite digging around for a bit in the related Rails 3 source files, I can't figure it out.
I know how to use url_for
and request
to build a path from the current route, but I don't know how to actually get to the ActionController::Routing::Route
that maps to the route url_for
is using. If I can get an instance of the route I need, I can just call Route#segment_keys and get what I need.
If anybody is interested, the reason I'm doing this is so I can toggle between resources with a select dropdown and stay on the current view that applies to the currently selected resource, but only if the current path doesn't contain nested paths (i.e. toggle /resources/1/edit
to /resources/2/edit
but do not toggle between /resources/1/subresources/1
to /resources/2/subresources/1
because subresource
number 1 is not a child of resource
2).