# Rails, REST, and Routes

**URL:** <https://www.ruby-forum.com/t/rails-rest-and-routes/88045>\
**Category:** Rails\
**Created:** [March 7, 2007, 6:44pm UTC](https://www.ruby-forum.com/t/rails-rest-and-routes/88045 "2007-03-07T18:44:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![claycle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b487fb/32.png) [@claycle](https://www.ruby-forum.com/u/claycle)\
**Post date:** [March 7, 2007, 6:44pm UTC](https://www.ruby-forum.com/t/rails-rest-and-routes/88045/1 "2007-03-07T18:44:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![claycle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b487fb/32.png) [@claycle](https://www.ruby-forum.com/u/claycle)\
**Post date:** [March 7, 2007, 7:48pm UTC](https://www.ruby-forum.com/t/rails-rest-and-routes/88045/2 "2007-03-07T19:48:28Z")

</div>

OK, I think I am getting closer:

I added the following to my routes:

map.resources :boxes  
map.resources :boxes, :path\_prefix =\> “/boxes/:parent\_id”,  
:name\_prefix =\> “child\_”

…still chugging…
