I’m working on a rails application which is built around a tree data structure. As such, the index of the controller displays the root node of said structure. Demonstration is probably easier to explain what I want:
/place/1 == place
can I restfully define such that
/place/1/photos == place/photos
and
/place/1/photos/1 == place/photos/1
etc?
Ideally what I’d like is that the articles url and its nested resource urls work by default such that I don’t need to change a whole bunch of stuff and conditionally generate paths all over the place.
Thanks in advance for any help. 🙂
You could have the usual nested restful routes (it’s good to keep them as the baseline, and to use them for the non-sexy urls like update, create, etc) and then add some custom routes for your ‘pretty’ urls:
you could then add a bit of logic into the photos controller to make sure you have the place even if you didn’t get params[:place_id], eg
The main thing to watch out for in custom urls is that you don’t create any conflict with a) the regular restful urls or b) your other custom urls.