Piers is dead on. I really hope that Rails will add support for
simpler identification of resources.
AFAICS, ordered hashs are not supported in Ruby 1.8 (but are Ruby
1.9). But a nested hash would also solve the problem of identifying
the hierarchy. In fact, I made a ticket just for such an enhancement
(http://dev.rubyonrails.org/ticket/8105) over a year ago. And while
it may not be a practical solution, my ticket and Piers wish are
pretty much one and the same: ease the burden for identifying nested
If we accept that a nested/ordered hash of params is not going to
happen any time soon (and I think that is the reality), then an
alternative is for the controller to examine the matched route and
"regenerate" the hierarchy manually. The ResourcesController plugin
does just that. It's not pretty how it get the job done, but it does
work very well if you don't look behind the curtain.
Full Circle REST is what I call this approach. By defining abstract
resources in routes.rb, it should be possible to...
1. Instantiate the appropriate controller (available now)
2. Identify the resources (including parent resources) in the
controller (missing, but available in RC)
3. Respond with content that includes links built by simple named
route url helpers (mostly available, but further abstracted by RC)
At every stage, the concept of "REST resource" is available to give
your application structure. Concrete resources are determined by the
request URL and used to determine the controller to instantiate. Then
they are available within that controller (hydrated selectively to
manage performance) and finally they are used to generate other links
in the content.
I've blogged here about how Rails could go about making step two (the
current squeaky wheel) easier: http://cho.hapgoods.com/wordpress/?p=151
Thanks also, Piers, for expressing my attachment to deep(er) urls.
Shallow URLs usually work, but they lack expressive context. In a
more flexible framework (and even in Rails, with some work), /forums/3/
posts/2 may mean the second post in forum 3, or even the second post
in the third forum and consequently /posts/2 alone is probably