Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for removing keys with nil values

  • Loading branch information...
commit 7f0dec6265de9f39b66127e039f99ddc337dd375 1 parent 51084b6
@jrust jrust authored
View
3  lib/action_view/helpers/hash_to_hidden_fields.rb
@@ -6,7 +6,8 @@ module ActionView
module Helpers
module HashToHiddenFields
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|
key, value = pair.split('=', 2).map { |str| Rack::Utils.unescape(str) }
View
1  spec/hash_to_hidden_fields_spec.rb
@@ -8,6 +8,7 @@
"nested1" => "3",
"nested2" => "4"
},
+ "nil" => nil,
"array" => [
1, 2, "3", "abc"
],
Please sign in to comment.
Something went wrong with that request. Please try again.