Skip to content
Browse files

RouteSet: optimize routes generation when globbing is used

  • Loading branch information...
1 parent 9de9e6a commit 1ab0523cfd405f2f8097841405947c0d26b72150 @bogdan bogdan 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 1ab0523

Please sign in to comment.
Something went wrong with that request. Please try again.