Permalink
Browse files

Add support for removing keys with nil values

  • Loading branch information...
Jason Rust
Jason Rust committed May 21, 2012
1 parent 51084b6 commit 7f0dec6265de9f39b66127e039f99ddc337dd375
Showing with 3 additions and 1 deletion.
  1. +2 −1 lib/action_view/helpers/hash_to_hidden_fields.rb
  2. +1 −0 spec/hash_to_hidden_fields_spec.rb
@@ -6,7 +6,8 @@ module ActionView
module Helpers module Helpers
module HashToHiddenFields module HashToHiddenFields
def hash_to_hidden_fields(hash) def hash_to_hidden_fields(hash)
pairs = hash.to_query.split(Rack::Utils::DEFAULT_SEP) cleaned_hash = hash.reject { |k, v| v.nil? }
pairs = cleaned_hash.to_query.split(Rack::Utils::DEFAULT_SEP)
tags = pairs.map do |pair| tags = pairs.map do |pair|
key, value = pair.split('=', 2).map { |str| Rack::Utils.unescape(str) } key, value = pair.split('=', 2).map { |str| Rack::Utils.unescape(str) }
@@ -8,6 +8,7 @@
"nested1" => "3", "nested1" => "3",
"nested2" => "4" "nested2" => "4"
}, },
"nil" => nil,
"array" => [ "array" => [
1, 2, "3", "abc" 1, 2, "3", "abc"
], ],

0 comments on commit 7f0dec6

Please sign in to comment.