Browse files

Merge pull request #6144 from bogdan/routes

RouteSet: optimize routes generation when globbing is used
  • Loading branch information...
2 parents 9de9e6a + 1ab0523 commit c1f4cb59acad9f82ad26f8103045bcddce9ca4f4 @josevalim josevalim committed May 3, 2012
Showing with 5 additions and 2 deletions.
  1. +5 −2 actionpack/lib/action_dispatch/routing/route_set.rb
View
7 actionpack/lib/action_dispatch/routing/route_set.rb
@@ -202,7 +202,7 @@ def #{selector}(*args)
# Clause check about when we need to generate an optimized helper.
def optimize_helper?(route) #:nodoc:
- route.ast.grep(Journey::Nodes::Star).empty? && route.requirements.except(:controller, :action).empty?
+ route.requirements.except(:controller, :action).empty?
end
# Generates the interpolation to be used in the optimized helper.
@@ -214,7 +214,10 @@ def optimized_helper(route)
end
route.required_parts.each_with_index do |part, i|
- string_route.gsub!(part.inspect, "\#{Journey::Router::Utils.escape_fragment(args[#{i}].to_param)}")
+ # Replace each route parameter
+ # e.g. :id for regular parameter or *path for globbing
+ # with ruby string interpolation code
+ string_route.gsub!(/(\*|:)#{part}/, "\#{Journey::Router::Utils.escape_fragment(args[#{i}].to_param)}")
end
string_route

0 comments on commit c1f4cb5

Please sign in to comment.