Skip to content

Instantly share code, notes, and snippets.

@ndbroadbent
Created February 12, 2013 00:24
Show Gist options
  • Save ndbroadbent/4758944 to your computer and use it in GitHub Desktop.
Save ndbroadbent/4758944 to your computer and use it in GitHub Desktop.
Save this to config/initializers/json_munging_patch.rb until https://github.com/rails/rails/pull/8862 or an alternative fix is merged.
# Patch from https://github.com/rails/rails/pull/8862
module ActionDispatch
Request.class_eval do
# Remove nils from the params hash
def deep_munge(hash)
hash.each do |k, v|
case v
when Array
if v.size > 0 && v.all?(&:nil?)
hash[k] = nil
next
end
v.grep(Hash) { |x| deep_munge(x) }
v.compact!
when Hash
deep_munge(v)
end
end
hash
end
end
end
@abuiles
Copy link

abuiles commented Nov 5, 2013

@ndbroadbent seem like this wasn't applied?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment