mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Routes: *path items should use arrays #883
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@954 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
eb73846f48
commit
b88fa4d1df
3 changed files with 26 additions and 6 deletions
|
@ -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 @@ 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
|
||||
|
||||
|
@ -64,7 +65,12 @@ module ActionController
|
|||
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 @@ module ActionController
|
|||
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 @@ class RouteTests < Test::Unit::TestCase
|
|||
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'
|
||||
|
|
Loading…
Reference in a new issue