Nest RESTful routes with namespaces?

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

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...

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. }}}

Thorsten Mueller 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. :slight_smile:

Thanks you guys!