mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added arrays as a value option for params in url_for and friends #467 [Eric Anderson]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@403 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
1d61071e7c
commit
9c09f81bc6
3 changed files with 23 additions and 2 deletions
|
@ -1,5 +1,10 @@
|
|||
*SVN*
|
||||
|
||||
* Added arrays as a value option for params in url_for and friends #467 [Eric Anderson]. Example:
|
||||
|
||||
url_for(:controller => 'user', :action => 'delete', :params => { 'username' => %( paul john steve ) } )
|
||||
# => /user/delete?username[]=paul&username[]=john&username[]=steve
|
||||
|
||||
* Fixed that controller tests can now assert on the use of cookies #466 [Alexey]
|
||||
|
||||
* Fixed that send_file would "remember" all the files sent by adding to the headers again and again #458 [bitsweat]
|
||||
|
|
|
@ -174,7 +174,12 @@ module ActionController
|
|||
elements = []
|
||||
query_string = ""
|
||||
|
||||
hash.each { |key, value| elements << "#{CGI.escape(key)}=#{CGI.escape(value.to_s)}" }
|
||||
hash.each do |key, value|
|
||||
key = CGI.escape key
|
||||
key += '[]' if value.class == Array
|
||||
value = [ value ] unless value.class == Array
|
||||
value.each { |val| elements << "#{key}=#{CGI.escape(val.to_s)}" }
|
||||
end
|
||||
unless elements.empty? then query_string << ("?" + elements.join("&")) end
|
||||
|
||||
return query_string
|
||||
|
|
|
@ -246,7 +246,18 @@ class UrlTest < Test::Unit::TestCase
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def test_parameters_with_array
|
||||
@clean_urls.each do |url|
|
||||
assert_equal(
|
||||
"http://www.singlefile.com/identity/show?id[]=3&id[]=5&id[]=10",
|
||||
url.rewrite(
|
||||
:action => "show",
|
||||
:params => { 'id' => [ 3, 5, 10 ] } )
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def test_action_with_id
|
||||
assert_equal(
|
||||
"http://www.singlefile.com/identity/show/7",
|
||||
|
|
Loading…
Reference in a new issue