diff --git a/actionpack/lib/action_dispatch/journey/route.rb b/actionpack/lib/action_dispatch/journey/route.rb index 1ba91d548ecc592cb5216379049008602694b939..9f0a3af902fa96d361efd2458e8ae6fe7b348b79 100644 --- a/actionpack/lib/action_dispatch/journey/route.rb +++ b/actionpack/lib/action_dispatch/journey/route.rb @@ -16,14 +16,6 @@ def initialize(name, app, path, constraints, defaults = {}) @app = app @path = path - # Unwrap any constraints so we can see what's inside for route generation. - # This allows the formatter to skip over any mounted applications or redirects - # that shouldn't be matched when using a url_for without a route name. - if app.is_a?(Routing::Mapper::Constraints) - app = app.app - end - @dispatcher = app.is_a?(Routing::RouteSet::Dispatcher) - @constraints = constraints @defaults = defaults @required_defaults = nil @@ -99,7 +91,7 @@ def glob? end def dispatcher? - @dispatcher + @app.dispatcher? end def matches?(request) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index c5e093dae5dcd694c13c7dab5a2d21c37b4da027..c7f6ff620eb6652cc4388fc07d3af76c8373893e 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -28,9 +28,16 @@ def initialize(app, constraints, request) app = app.app end + # Unwrap any constraints so we can see what's inside for route generation. + # This allows the formatter to skip over any mounted applications or redirects + # that shouldn't be matched when using a url_for without a route name. + @dispatcher = app.is_a?(Routing::RouteSet::Dispatcher) + @app, @constraints, @request = app, constraints, request end + def dispatcher?; @dispatcher; end + def matches?(env) req = @request.new(env) diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index f36453020f63d47f72af6d3644678d3b36d999c7..5839db87f9153b28f6bf15b097f358f52162c744 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -703,12 +703,10 @@ def recognize_path(path, environment = {}) end old_params = req.path_parameters req.path_parameters = old_params.merge params - dispatcher = route.app - if dispatcher.matches?(env) - dispatcher = dispatcher.app - end + app = route.app + if app.matches?(env) && app.dispatcher? + dispatcher = app.app - if dispatcher.is_a?(Dispatcher) if dispatcher.controller(params, false) dispatcher.prepare_params!(params) return params diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb index db2d3bc10d14130f7b5f98d766175e12f85a3ae1..561c547b444971694d61b93aec2c0398401f25f5 100644 --- a/actionpack/test/journey/router_test.rb +++ b/actionpack/test/journey/router_test.rb @@ -9,6 +9,7 @@ class StubDispatcher < Routing::RouteSet::Dispatcher def initialize super({}) end + def dispatcher?; true; end end attr_reader :routes