From 37a46151ec14ae11f5306d997b822f30be7a69d3 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 20 Mar 2005 14:04:33 +0000 Subject: Added path collection syntax for Routes that will gobble up the rest of the url and pass it on to the controller #830 [rayners] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@927 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/routing.rb | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 1aaa599b9e..c021d88ca9 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -48,12 +48,28 @@ module ActionController used_names = @requirements.inject({}) {|hash, (k, v)| hash[k] = true; hash} # Mark requirements as used so they don't get put in the query params components = @items.collect do |item| if item.kind_of? Symbol + collection = false + + if /^\*/ =~ item.to_s + collection = true + item = item.to_s.sub(/^\*/,"").intern + end + used_names[item] = true value = options[item] || defaults[item] || @defaults[item] return nil, requirements_for(item) unless passes_requirements?(item, value) + defaults = {} unless defaults == {} || value == defaults[item] # Stop using defaults if this component isn't the same as the default. - (value.nil? || item == :controller) ? value : CGI.escape(value.to_s) - else item + + if value.nil? || item == :controller + value + elsif collection + CGI.escape(value.to_s).gsub(/%2F/, "/") + else + CGI.escape(value.to_s) + end + else + item end end @@ -96,6 +112,10 @@ module ActionController end options[:controller] = controller_class.controller_path return nil, requirements_for(:controller) unless passes_requirements?(:controller, options[:controller]) + elsif /^\*/ =~ item.to_s + value = components.join("/") || @defaults[item] + components = [] + options[item.to_s.sub(/^\*/,"").intern] = value.nil? ? value : CGI.unescape(value) elsif item.kind_of? Symbol value = components.shift || @defaults[item] return nil, requirements_for(item) unless passes_requirements?(item, value) @@ -142,7 +162,7 @@ module ActionController end def items=(path) - items = path.split('/').collect {|c| (/^:(\w+)$/ =~ c) ? $1.intern : c} if path.kind_of?(String) # split and convert ':xyz' to symbols + items = path.split('/').collect {|c| (/^(:|\*)(\w+)$/ =~ c) ? (($1 == ':' ) ? $2.intern : "*#{$2}".intern) : c} if path.kind_of?(String) # split and convert ':xyz' to symbols items.shift if items.first == "" items.pop if items.last == "" @items = items @@ -172,6 +192,7 @@ module ActionController end end def requirements_for(name) + name = name.to_s.sub(/^\*/,"").intern if (/^\*/ =~ name.inspect) presence = (@defaults.key?(name) && @defaults[name].nil?) requirement = case @requirements[name] when nil then nil -- cgit v1.2.3