I am trying to figure out how to write a “slightly nested” RESTful route
to represent the following.
I have the concept of a Box. A Box may contain another Box. Here are the
URI’s and methods I wish to model – the first few are obvious…
GET /boxes
=> return index of boxes
GET /boxes/1
=> return box #1
POST /boxes
=> create a new box, returns URI of new box, eg
PUT /boxes/1
=> update box #1
DELETE /boxes/1
=> destroy box #1
The above are all well and good and handled fine by…
routes.rb:
map.resources :boxes
But I also want to map the following resources:
GET /boxes/1/boxes
=> Returns a list of boxes inside Box #1. NOTE: These URIs should be of
the form /boxes/#, NOT /boxes/1/boxes/#
POST /boxes/1/boxes
=> create a new box inside Box #1. The returned resource should be of
the form /boxes/#, NOT /boxes/1/boxes/#.
It’s these last two that I am having trouble with, trying to grok them.
Clues appreciated.