# REST & Routing: namespaces within resources

**URL:** <https://www.ruby-forum.com/t/rest-routing-namespaces-within-resources/148382>\
**Category:** Rails\
**Created:** [September 12, 2008, 11:43am UTC](https://www.ruby-forum.com/t/rest-routing-namespaces-within-resources/148382 "2008-09-12T11:43:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattwynne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecc23a/32.png) [@mattwynne](https://www.ruby-forum.com/u/mattwynne)\
**Post date:** [September 12, 2008, 11:43am UTC](https://www.ruby-forum.com/t/rest-routing-namespaces-within-resources/148382/1 "2008-09-12T11:43:17Z")

</div>

I know I can use a namespace on the map passed into the block for  
ActionController::Routing::Routes.draw because I’ve done that with  
some Admin:: controllers.

What I want to do is something similar with controllers for resources  
that belong to another resource.

Is it possible to do something like this:

map.resources :shops do |shop|

shop.resource :shopkeeper

shop.namespace |goods| do  
goods.resources :sweets  
goods.resources :beer  
goods.resources :shoes  
end

end

so that I can have URLs like

/shops/123/goods/sweets  
/shops/123/goods/beer

and controllers like

Goods::SweetsController  
Goods::ShoesController

I had a go at this but it doesn’t seem to work - and I thought I’d ask  
whether it was possible before I waste too much time on it.

---

<div class="post-metadata">

**Author:** ![mattwynne](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecc23a/32.png) [@mattwynne](https://www.ruby-forum.com/u/mattwynne)\
**Post date:** [September 13, 2008, 7:10pm UTC](https://www.ruby-forum.com/t/rest-routing-namespaces-within-resources/148382/2 "2008-09-13T19:10:50Z")

</div>

On Sep 12, 5:28 pm, mattwynne [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> so that I can have URLs like  
> whether it was possible before I waste too much time on it.  
> That should work, just correct your namespace definition:

shop.namespace :goods do |goods|  
goods.resources :sweets  
goods.resources :beer  
goods.resources :shoes  
end
