开发者

can't escape out of 2 levels of nested route namespaces using url_for

I have 3 levels of nested routes in my Rails 3.0.10 application. like this:

resources :foo
namespace :bar do
  resources :foo
  namespace :baz do
    resources :foo
  end
end

when in controllers foo or bar/foo all seems to work fine, but once I get into controller bar/baz/foo I can't get a routing to the 1st level controller.

Example code:

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

bar/foo_controller.rb:

module Bar
  class FooController < ApplicationController
    def index
      render :text => urls_dump
    end
  end
end

bar/baz/foo_controller.rb:

module Bar
  module Baz
    class FooController < ApplicationController
      def index
        render :text => urls_dump
      end
    end
  end
end

not when I try to access them:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜