# Nested REST resource routes without controller name

**URL:** <https://www.ruby-forum.com/t/nested-rest-resource-routes-without-controller-name/112266>\
**Category:** Rails\
**Created:** [August 16, 2007, 10:40pm UTC](https://www.ruby-forum.com/t/nested-rest-resource-routes-without-controller-name/112266 "2007-08-16T22:40:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [August 16, 2007, 10:40pm UTC](https://www.ruby-forum.com/t/nested-rest-resource-routes-without-controller-name/112266/1 "2007-08-16T22:40:11Z")

</div>

I am curious if the following URL pattern is appropriate to use with  
REST and map.resources:

Let’s say I want to build a website with information about cars. I  
decide that there will be a page to view/manage cars by model. The  
route for this is easily created:

map.resources :cars

The URLs look great. But now I want to introduce the ability to  
specify cars by year. I can do this by modifying the existing route:

map.resources :cars do |car|  
car.resources :years  
end

However, this leads to an undesirable URL pattern. To view a 1998  
Corvette, I need to point my browser at /cars/corvette/years/1998.  
What I wanted was /car/corvette/1998. In addition, the /car/corvette  
URL would enumerate all years that the corvette was produced. I want a  
POST request on /car/corvette to be used for adding new years.

Essentially, I want the ability to nest resources, without specifying  
the nested resource name. I know how to do this without using the  
resources API, so I’m not looking for a workaround.

In the CarsController, I would access a car with params[:id]. In the  
CarYearsController, I would access a particular year of a car by using  
params[:car] and params[:id]. (The :id would be the year). Is this  
just a bad idea?

---

<div class="post-metadata">

**Author:** ![matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@matt](https://www.ruby-forum.com/u/matt)\
**Post date:** [August 16, 2007, 10:47pm UTC](https://www.ruby-forum.com/t/nested-rest-resource-routes-without-controller-name/112266/2 "2007-08-16T22:47:16Z")

</div>

It looks like someone else has already asked this question, but there  
was no feedback:  
[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/c21c7f2667f55841/11c41b6455eb44a2?lnk=gst&q=nesting+resources&rnum=7#11c41b6455eb44a2](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/c21c7f2667f55841/11c41b6455eb44a2?lnk=gst&q=nesting+resources&rnum=7#11c41b6455eb44a2)
