aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-03-20 14:04:33 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-03-20 14:04:33 +0000
commit37a46151ec14ae11f5306d997b822f30be7a69d3 (patch)
tree40d12bfc04ce9bd1bc90596ef966b5cc218f38f8 /actionpack/lib/action_controller
parentce9a9433b38b6f7dc024ec249cadc92a4ab4533c (diff)
downloadrails-37a46151ec14ae11f5306d997b822f30be7a69d3.tar.gz
rails-37a46151ec14ae11f5306d997b822f30be7a69d3.tar.bz2
rails-37a46151ec14ae11f5306d997b822f30be7a69d3.zip
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
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r--actionpack/lib/action_controller/routing.rb27
1 files changed, 24 insertions, 3 deletions
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