简体   繁体   English

Rails中的命名空间路由1

[英]Namespaced routes in rails 1

I'm working with some legacy code with the last version of rails 1. Upgrading to a later version of rails isn't possible and as such map.namespace is a private method in this version, otherwise I'd be using it. 我正在使用Rails 1的最新版本处理一些旧代码。无法升级到Rails的更高版本,因此map.namespace是此版本中的私有方法,否则我会使用它。

I have several resources which I have nested into a submenu for simplicity. 为了简单起见,我将一些资源嵌套到一个子菜单中。 Their controllers are all within the folder of that submenu and all inherit that controller's namespace. 它们的控制器都在该子菜单的文件夹中,并且都继承该控制器的名称空间。

I'm having major issues with the sub elements. 我在子元素方面遇到重大问题。 I have mapped the resources and applied a prefix to them in the form of 我已经映射了资源,并以以下形式对它们应用了前缀

map.resources :subitem, :path_prefix => "/sub_menu"

but I'm having major issues with using RESTFul methods on these nested objects. 但是在这些嵌套对象上使用RESTFul方法时遇到了主要问题。 The paths that I'm trying to use, say to delete an object simply do not work. 我尝试使用的路径(例如删除对象)根本不起作用。

I'm refactoring this current code base so there's very little I can do, and there's very little I can find on rails 1 routes online. 我正在重构此当前代码库,因此我几乎无能为力,而且在在线1条路线上我几乎找不到。 It's a bit of a finicky issue but maybe I've missed something simple about routes. 这是一个挑剔的问题,但也许我错过了一些简单的路线。

Do I simply need to manually write out every particular route I can use and then manually prefix it, or is there a simpler way? 我是否只需要手动写出我可以使用的每条特定路由,然后手动为其添加前缀,还是有更简单的方法?

My other routes work fine, I simply cannot use the 我的其他路线工作正常,我根本无法使用

subitem_path(subitem) :method => :delete

function in my link to 在我的链接中起作用

So I figured out how to layout the routes appropriately so I could access the paths 所以我想出了如何适当地布置路线,以便可以访问路径

Add to the above route the specified controller you're using and the routes will map accordingly 将您正在使用的指定控制器添加到上述路由中,路由将进行相应映射

map.resources :subitem, :path_prefix => "/sub_menu, :controller => "submenu/subitem"

Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM