Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ol - fix recognize_path for not being able to parse engine routes in … #21494

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 18 additions & 8 deletions actionpack/lib/action_dispatch/routing/route_set.rb
Expand Up @@ -737,18 +737,28 @@ def recognize_path(path, environment = {})
old_params = req.path_parameters
req.path_parameters = old_params.merge params
app = route.app
if app.matches?(req) && app.dispatcher?
begin
req.controller_class
rescue NameError
raise ActionController::RoutingError, "A route matches #{path.inspect}, but references missing controller: #{params[:controller].camelize}Controller"
if app.matches?(req)
if app.dispatcher? #RouteSet::Dispatcher
begin
req.controller_class
rescue NameError
raise ActionController::RoutingError, "A route matches #{path.inspect}, but references missing controller: #{params[:controller].camelize}Controller"
end
return req.path_parameters
else #Mapper::Constraints (engine case)
engine_klass = app.app
req.path_info = Journey::Router::Utils.normalize_path(req.path_info)
params = engine_klass.routes.recognize_path(req.path_info, {engine: engine_klass})
return params
end

return req.path_parameters
end
end

raise ActionController::RoutingError, "No route matches #{path.inspect}"
if environment[:engine]
raise ActionController::RoutingError, "No route matches #{path.inspect} in #{environment[:engine]}"
else
raise ActionController::RoutingError, "No route matches #{path.inspect}"
end
end
end
# :startdoc:
Expand Down
10 changes: 10 additions & 0 deletions actionpack/test/controller/integration_test.rb
Expand Up @@ -859,6 +859,16 @@ def app
self.class
end

test "recognize_path for mounted engine in main_app" do
parsed_path = self.class.routes.recognize_path('/mounted/baz')
assert_equal "application_integration_test/test", parsed_path[:controller]
assert_equal "index", parsed_path[:action]
exception = assert_raises(ActionController::RoutingError) do
ApplicationIntegrationTest.routes.recognize_path('/mounted/unknown')
end
assert_equal "No route matches \"/unknown\" in ApplicationIntegrationTest::MountedApp", exception.message
end

test "includes route helpers" do
assert_equal '/', empty_string_path
assert_equal '/foo', foo_path
Expand Down