aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/info_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails/info_controller.rb')
-rw-r--r--railties/lib/rails/info_controller.rb25
1 files changed, 23 insertions, 2 deletions
diff --git a/railties/lib/rails/info_controller.rb b/railties/lib/rails/info_controller.rb
index 49e5431a16..778105c5f7 100644
--- a/railties/lib/rails/info_controller.rb
+++ b/railties/lib/rails/info_controller.rb
@@ -17,7 +17,28 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc:
end
def routes
- @routes_inspector = ActionDispatch::Routing::RoutesInspector.new(_routes.routes)
- @page_title = 'Routes'
+ if path = params[:path]
+ path = URI.parser.escape path
+ normalized_path = with_leading_slash path
+ render json: {
+ exact: match_route {|it| it.match normalized_path },
+ fuzzy: match_route {|it| it.spec.to_s.match path }
+ }
+ else
+ @routes_inspector = ActionDispatch::Routing::RoutesInspector.new(_routes.routes)
+ @page_title = 'Routes'
+ end
+ end
+
+ private
+
+ def match_route
+ _routes.routes.select {|route|
+ yield route.path
+ }.map {|route| route.path.spec.to_s }
+ end
+
+ def with_leading_slash(path)
+ ('/' + path).squeeze('/')
end
end