我的Rails 3.0.10应用程序中有3个级别的嵌套路由。像这样:
resources :foo
namespace :bar do
resources :foo
namespace :baz do
resources :foo
end
end
当在控制器foo或bar / foo中似乎一切正常时,但是一旦我进入控制器栏/ baz / foo,我就无法获得到第一级控制器的路由。
示例代码:
application_controller.rb:
class ApplicationController < ActionController::Base
protect_from_forgery
def urls_dump
[
{:controller => "foo"},
{:controller => "/foo"},
].map do |opts|
begin
url_for(opts.dup)
rescue => e
"BAD: #{opts.inspect}: #{e}"
end
end.join("\n") + "\n"
end
end
foo_controller.rb:
class FooController < ApplicationController
def index
render :text => urls_dump
end
end
酒吧/ foo_controller.rb:
module Bar
class FooController < ApplicationController
def index
render :text => urls_dump
end
end
end
酒吧/巴兹/ foo_controller.rb:
module Bar
module Baz
class FooController < ApplicationController
def index
render :text => urls_dump
end
end
end
end
当我尝试访问它们时不是:
✗ curl http://localhost:3000/foo
http://localhost:3000/foo
http://localhost:3000/foo
✗ curl http://localhost:3000/bar/foo
http://localhost:3000/bar/foo
http://localhost:3000/foo
✗ curl http://localhost:3000/bar/baz/foo
http://localhost:3000/bar/baz/foo
BAD: {:controller=>"/foo"}: No route matches {:controller=>"bar//foo"}