diff options
author | Richard Schneeman <richard.schneeman@gmail.com> | 2015-02-26 12:59:43 -0600 |
---|---|---|
committer | Richard Schneeman <richard.schneeman@gmail.com> | 2015-02-26 12:59:43 -0600 |
commit | f069b413216f207056b4e46ba302afc646201c1e (patch) | |
tree | 5929bf874785b529cba45a1fddac09e0b435a667 /railties/lib | |
parent | 28778de2e0bf556af23ac7a0080174dae6e687cc (diff) | |
parent | 321db4aa2edf46b8cf54c99bf3b97b48b7099dcf (diff) | |
download | rails-f069b413216f207056b4e46ba302afc646201c1e.tar.gz rails-f069b413216f207056b4e46ba302afc646201c1e.tar.bz2 rails-f069b413216f207056b4e46ba302afc646201c1e.zip |
Merge pull request #18434 from brainopia/change_filter_on_rails_info_routes
Change filter on /rails/info/routes to use an actual path regexp from rails
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/info_controller.rb | 25 |
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..6e61cc3cb5 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.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 |