Petecocoon
Petecocoon

Reputation: 23

Nested resource in Rails3, no route match

I have a nested route in rails 3 mapped as

resources :maps do
    resource :versions
    member do
        post 'share'
        get  'share'            
    end

end

but when i try to connect to http://localhost:3000/maps/35/versions/2 i obtains

No route matches "/maps/35/versions/2"

and in rake routes GET /maps/:map_id/versions/:id(.:format) {:controller=>"versions", :action=>"show"} or similar (with :id) is missing other routes with versions works correctly

what's wrong?

EDIT 2: This is the full rake routes output

maps_public GET    /maps/public(.:format)                 {:controller=>"maps", :action=>"public"}
            map_versions POST   /maps/:map_id/versions(.:format)       {:controller=>"versions", :action=>"create"}
        new_map_versions GET    /maps/:map_id/versions/new(.:format)   {:controller=>"versions", :action=>"new"}
       edit_map_versions GET    /maps/:map_id/versions/edit(.:format)  {:controller=>"versions", :action=>"edit"}
                         GET    /maps/:map_id/versions(.:format)       {:controller=>"versions", :action=>"show"}
                         PUT    /maps/:map_id/versions(.:format)       {:controller=>"versions", :action=>"update"}
                         DELETE /maps/:map_id/versions(.:format)       {:controller=>"versions", :action=>"destroy"}
               share_map POST   /maps/:id/share(.:format)              {:controller=>"maps", :action=>"share"}
                         GET    /maps/:id/share(.:format)              {:controller=>"maps", :action=>"share"}
                    maps GET    /maps(.:format)                        {:controller=>"maps", :action=>"index"}
                         POST   /maps(.:format)                        {:controller=>"maps", :action=>"create"}
                 new_map GET    /maps/new(.:format)                    {:controller=>"maps", :action=>"new"}
                edit_map GET    /maps/:id/edit(.:format)               {:controller=>"maps", :action=>"edit"}
                     map GET    /maps/:id(.:format)                    {:controller=>"maps", :action=>"show"}
                         PUT    /maps/:id(.:format)                    {:controller=>"maps", :action=>"update"}
                         DELETE /maps/:id(.:format)                    {:controller=>"maps", :action=>"destroy"}

Upvotes: 1

Views: 516

Answers (2)

dogenpunk
dogenpunk

Reputation: 4382

In addition to @Femaref's answer, the url you need to access is /maps/35/versions/2. If you want the singular (singleton) resource, then you'd do:

resources :maps do
  resource :version
end

And then hit /maps/35/version (doesn't take an id). Which, if you have multiple versions for each map, you probably don't want to do.

Upvotes: 1

Femaref
Femaref

Reputation: 61497

It has to be resources :versions. Note the missing "s" in your case.

Upvotes: 3

Related Questions