Rails3 中的嵌套资源,没有路由匹配

发布于 2024-12-10 12:34:59 字数 2439 浏览 1 评论 0原文

我在 Rails 3 中有一个嵌套路由映射为,

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

end

但是当我尝试连接到 http://localhost: 3000/maps/35/versions/2 我获得

没有路由匹配“/maps/35/versions/2”

并且在rake路由中 GET /maps/:map_id/versions/:id(.:format) {:controller=>"versions", :action=>"show"} 或类似(带有:id)丢失 其他版本的路由工作正常,

出了什么问题?

编辑2: 这是完整的 rake 路线输出

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情绪少女 2024-12-17 12:34:59

它必须是资源:版本。请注意您的案例中缺少的“s”。

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

巷子口的你 2024-12-17 12:34:59

除了@Femaref的答案之外,您需要访问的网址是/maps/35/versions/2。如果您想要单一(单例)资源,那么您可以这样做:

resources :maps do
  resource :version
end

然后点击 /maps/35/version (不带 id)。如果每个地图都有多个版本,您可能不想这样做。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文