Created
December 29, 2009 16:02
-
-
Save cch1/265388 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Recursively coerce empty string values in hash -particularly | |
# useful for HTTP POSTed forms. | |
# Values are coerced based on the rules mapping of params_hash keys to coerced values. | |
# See http://dev.rubyonrails.org/ticket/5694 for background | |
def self.coerce_empty_strings(params_hash, rules = {}) | |
return unless params_hash | |
params_hash.each_pair do |k,v| | |
# AR::Base.extract_callstack_for_multiparameter_attributes can't handle nil values | |
unless k.include?('(') | |
params_hash[k] = rules[k.to_sym] if v.kind_of?(String) && v.empty? | |
params_hash[k] = coerce_empty_strings(v) if v.kind_of?(Hash) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment