aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/journey
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2013-03-03 19:18:01 +0000
committerAndrew White <andyw@pixeltrix.co.uk>2013-03-03 19:18:01 +0000
commit86cf7a2d166430fac1611aa7593b52b46eeb9f70 (patch)
tree998de220aab255a787bfbcf21341e71f5b6e6edb /actionpack/lib/action_dispatch/journey
parent48c21e3255fa2f4b1875ca8616a5ad7706a7a4cb (diff)
downloadrails-86cf7a2d166430fac1611aa7593b52b46eeb9f70.tar.gz
rails-86cf7a2d166430fac1611aa7593b52b46eeb9f70.tar.bz2
rails-86cf7a2d166430fac1611aa7593b52b46eeb9f70.zip
Use custom visitor class for optimized url helpers
Rather than trying to use gsub to remove the optional route segments, which will fail with nested optional segments, use a custom visitor class that returns a empty string for group nodes. Closes #9524
Diffstat (limited to 'actionpack/lib/action_dispatch/journey')
-rw-r--r--actionpack/lib/action_dispatch/journey/route.rb4
-rw-r--r--actionpack/lib/action_dispatch/journey/visitors.rb8
2 files changed, 12 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/journey/route.rb b/actionpack/lib/action_dispatch/journey/route.rb
index 063302e0f2..6fda085681 100644
--- a/actionpack/lib/action_dispatch/journey/route.rb
+++ b/actionpack/lib/action_dispatch/journey/route.rb
@@ -71,6 +71,10 @@ module ActionDispatch
Visitors::Formatter.new(path_options).accept(path.spec)
end
+ def optimized_path
+ Visitors::OptimizedPath.new.accept(path.spec)
+ end
+
def optional_parts
path.optional_names.map { |n| n.to_sym }
end
diff --git a/actionpack/lib/action_dispatch/journey/visitors.rb b/actionpack/lib/action_dispatch/journey/visitors.rb
index 46bd58c178..2964d80d9f 100644
--- a/actionpack/lib/action_dispatch/journey/visitors.rb
+++ b/actionpack/lib/action_dispatch/journey/visitors.rb
@@ -74,6 +74,14 @@ module ActionDispatch
end
end
+ class OptimizedPath < String # :nodoc:
+ private
+
+ def visit_GROUP(node)
+ ""
+ end
+ end
+
# Used for formatting urls (url_for)
class Formatter < Visitor # :nodoc:
attr_reader :options, :consumed