Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for integers as array values

  • Loading branch information...
commit 51084b66872a0fd5b1328a09994cf526470057fb 1 parent 27308b7
Jason Rust jrust authored
6 lib/action_view/helpers/hash_to_hidden_fields.rb
View
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/object/to_query'
require 'action_view'
require 'action_view/helpers'
@@ -5,8 +6,7 @@ module ActionView
module Helpers
module HashToHiddenFields
def hash_to_hidden_fields(hash)
- query_string = Rack::Utils.build_nested_query(hash)
- pairs = query_string.split(Rack::Utils::DEFAULT_SEP)
+ pairs = hash.to_query.split(Rack::Utils::DEFAULT_SEP)
tags = pairs.map do |pair|
key, value = pair.split('=', 2).map { |str| Rack::Utils.unescape(str) }
@@ -17,4 +17,4 @@ def hash_to_hidden_fields(hash)
end
end
end
-end
+end
4 spec/hash_to_hidden_fields_spec.rb
View
@@ -9,7 +9,7 @@
"nested2" => "4"
},
"array" => [
- "1", "2", "3", "abc"
+ 1, 2, "3", "abc"
],
"array of hashes" => [
{ "key 1" => "val 1" },
@@ -56,4 +56,4 @@
@hash_to_hidden_fields.size.should == expected_html_blocks.join("\n").size
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.