# Nest RESTful routes with namespaces?

**URL:** <https://www.ruby-forum.com/t/nest-restful-routes-with-namespaces/132485>\
**Category:** Rails\
**Created:** [March 20, 2008, 5:28pm UTC](https://www.ruby-forum.com/t/nest-restful-routes-with-namespaces/132485 "2008-03-20T17:28:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [March 20, 2008, 5:28pm UTC](https://www.ruby-forum.com/t/nest-restful-routes-with-namespaces/132485/1 "2008-03-20T17:28:58Z")

</div>

Hi all

I have the following website structure:

In the namespace “music” I have artists, styles and labels, where  
artists also acts as namespace containing types:

map.namespace :music do |music|  
music.resources :artists  
music.namespace :artists do |artists|  
artists.resources :types  
end  
music.resources :styles  
music.resources :labels  
end

So I’d expect the following URL structure:

music/artists  
music/artists/types  
music/styles  
music/labels

Everything works great, except when opening music/artists/types I get  
the exception

NoMethodError in Music/artists/types#show

Showing music/artists/types/show.html.erb where line #2 raised:

undefined method `edit\_music\_artists\_types\_path’ for  
#ActionView::Base:0x24207a0

Extracted source (around line #2):

1:  
2: \<%= link\_to ‘Edit’,  
edit\_music\_artists\_types\_path(@music\_artist\_types) %\> |  
3: \<%= link\_to ‘Back’, music\_artists\_types\_path %\>

Anyone sees the problem…? Isn’t it possible to use :artists als  
namespace?

Thanks a lot,  
Josh

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [March 20, 2008, 5:42pm UTC](https://www.ruby-forum.com/t/nest-restful-routes-with-namespaces/132485/2 "2008-03-20T17:42:54Z")

</div>

the edit action requires a singular methof

edit\_music\_artists\_type\_path(id)

you’re using the plural.  
most likely that’s it. otherwise it’s more likely, that types or type is  
a ruby keyword than artists.

oops, just realize, you’re using a namespace, that’s the same name as a  
controller, that most likely won’t work…

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [March 21, 2008, 2:28am UTC](https://www.ruby-forum.com/t/nest-restful-routes-with-namespaces/132485/3 "2008-03-21T02:28:09Z")

</div>

On Fri, Mar 21, 2008 at 12:28 AM, Joshua M.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> map.namespace :music do |music|  
> music.resources :artists  
> music.namespace :artists do |artists|  
> artists.resources :types  
> end  
> music.resources :styles  
> music.resources :labels  
> end

[http://api.rubyonrails.org/classes/ActionController/Routing/RouteSet/Mapper.html](http://api.rubyonrails.org/classes/ActionController/Routing/RouteSet/Mapper.html)

Sniffer from the docs:  
{{{  
namespace(name, options = {}, &block)

Enables the use of resources in a module by setting the name\_prefix,  
path\_prefix, and namespace for the model. Example:

map.namespace(:admin) do |admin|  
admin.resources :products,  
:has\_many =\> [:tags, :images, :variants]  
end

This will create admin\_products\_url pointing to “admin/products”,  
which will look for an Admin::ProductsController. It’ll also create  
admin\_product\_tags\_url pointing to  
“admin/products/#{product\_id}/tags”, which will look for  
Admin::TagsController.  
}}}

–  
Regards,  
Josh.Yin/e$B]V3$L@e(B/A.K.A epaulin

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [March 21, 2008, 4:10pm UTC](https://www.ruby-forum.com/t/nest-restful-routes-with-namespaces/132485/4 "2008-03-21T16:10:46Z")

</div>

Thorsten M. wrote:

> the edit action requires a singular methof
> 
> edit\_music\_artists\_type\_path(id)
> 
> you’re using the plural.  
> most likely that’s it. otherwise it’s more likely, that types or type is  
> a ruby keyword than artists.
> 
> oops, just realize, you’re using a namespace, that’s the same name as a  
> controller, that most likely won’t work…

Surprisingly this really was the problem. I changed it to the singular  
form, and now it works perfectly. So it seems not to be any problem to  
nest namespaces and resources. 🙂

Thanks you guys!
