Routes: *path items should use arrays #883

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@954 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 eb73846f
......@@ -55,7 +55,9 @@
map.connect 'categories/*path_info', :controller => 'categories', :action => 'show'
A request for /categories/top-level-cat, would give @params[:path_info] with "top-level-cat".
A request for /categories/top-level-cat/level-1-cat, would give @params['path_info'] with "top-level-cat/level-1-cat" and so forth.
A request for /categories/top-level-cat/level-1-cat, would give @params[:path_info] with "top-level-cat/level-1-cat" and so forth.
The @params[:path_info] return is really an array, but where to_s has been overwritten to do join("/").
* Fixed options_for_select on selected line issue #624 [Florian Weber]
......
......@@ -47,6 +47,7 @@ def generate(options, defaults={})
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
......@@ -64,7 +65,12 @@ def generate(options, defaults={})
if value.nil? || item == :controller
value
elsif collection
Routing.extract_parameter_value(value).gsub(/%2F/, "/")
if value.kind_of?(Array)
value = value.collect {|v| Routing.extract_parameter_value(v)}.join('/')
else
value = Routing.extract_parameter_value(value).gsub(/%2F/, "/")
end
value
else
Routing.extract_parameter_value(value)
end
......@@ -113,9 +119,11 @@ def recognize(components, options={})
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]
value = components.empty? ? @defaults[item].clone : components.clone
value.collect! {|c| CGI.unescape c}
components = []
options[item.to_s.sub(/^\*/,"").intern] = value.nil? ? value : CGI.unescape(value)
def value.to_s() self.join('/') end
options[item.to_s.sub(/^\*/,"").intern] = value
elsif item.kind_of? Symbol
value = components.shift || @defaults[item]
return nil, requirements_for(item) unless passes_requirements?(item, value)
......
......@@ -329,11 +329,21 @@ def test_expand_controller_path_nested_no_leftover
def test_path_collection
route '*path_info', :controller => 'content', :action => 'fish'
verify_recognize'path/with/slashes',
:controller => 'content', :action => 'fish', :path_info => 'path/with/slashes'
:controller => 'content', :action => 'fish', :path_info => %w(path with slashes)
verify_generate('path/with/slashes', {},
{:controller => 'content', :action => 'fish', :path_info => 'path/with/slashes'},
{:controller => 'content', :action => 'fish', :path_info => 'path/with/slashes'},
{})
end
def test_path_collection_with_array
route '*path_info', :controller => 'content', :action => 'fish'
verify_recognize'path/with/slashes',
:controller => 'content', :action => 'fish', :path_info => %w(path with slashes)
verify_generate('path/with/slashes', {},
{:controller => 'content', :action => 'fish', :path_info => %w(path with slashes)},
{})
end
def test_special_characters
route ':id', :controller => 'content', :action => 'fish'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册