Rails 2命名空间和浅层路由问题 [英] Rails 2 Namespace and Shallow Routes Issue
问题描述
我已经编写了特定Rails应用程序的管理区域,现在我可以将其设置为网站中自己的部分了.
I've written the admin area of a particular rails app and now I'm ready to set it as own section within the website.
因此,它将是/admin
Therefore, it will be /admin
但是,我不想在路由本身中以/admin的身份使用它,所以我希望减少一些不常见的事情,因此我在其前后添加了两个连字符.
However, I didn't want to have it as /admin within the route itself I wanted to have something less common, so I added a couple of hyphens before and after it.
因此路由为/-admin-/,名称空间为Admin.
So the route is /-admin-/ and the namespace is Admin.
使用:path_prefix =>"/-admin-"进行设置后,我具有以下代码块:
After setting this up using :path_prefix => "/-admin-", I have the following code block:
map.namespace "/-admin-/", :name_prefix => "", :path_prefix => "/-admin-" do |admin|
这适用于除浅路径以外的所有路径,相反,在rake路径输出中,输出为:
This works for all but shallow routes, instead, in the rake routes output the output is:
new_page GET /-admin-/areas/:area_id/pages/new(.:format) {:action=>"new", :controller=>"admin/pages"}
edit_admin_page GET /admin/pages/:id/edit(.:format) {:action=>"edit", :controller=>"admin/pages"}
admin_page GET /admin/pages/:id(.:format) {:action=>"show", :controller=>"admin/pages"}
PUT /admin/pages/:id(.:format) {:action=>"update", :controller=>"admin/pages"}
DELETE /admin/pages/:id(.:format) {:action=>"destroy", :controller=>"admin/pages"}
areas GET /-admin-/areas(.:format) {:action=>"index", :controller=>"admin/areas"}
POST /-admin-/areas(.:format) {:action=>"create", :controller=>"admin/areas"}
new_area GET /-admin-/areas/new(.:format) {:action=>"new", :controller=>"admin/areas"}
请注意,浅层路由的前缀是/admin/,而不是/-admin-/(它们的父路由).
Notice how the shallow-routed routes are prefixed as /admin/ and not as /-admin-/ (as are their parent routes).
关于如何解决此问题的任何想法?这是Rails中的错误,还是我需要解决?我尝试将:path_prefix添加到每个嵌套路由,但是它什么都没做?
Any ideas on how to get around this? Is this a bug in rails or do I need to work around it? I tried adding the :path_prefix to each nested route but it doesn't do anything?
有什么想法吗?
推荐答案
没有办法解决此问题.事实证明,将所有版本的Rails设置为浅"时,都会将URL及其资源名称分解为最低点.唯一的解决方案是手动设置所有资源路由,而无需使用map.resources
.
There is no way to get around this. Turns out that all versions of Rails will break down the URL and its resource names to their lowest points when they're set to shallow. The only solution to this is to set all of your resource routes manually without using map.resources
.
这篇关于Rails 2命名空间和浅层路由问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!