-
-
Save bashcoder/33495ba9fbc59a467b0f to your computer and use it in GitHub Desktop.
Put "repair_empty_param_associations" in your before filters in the application_controller.rb
This file contains hidden or 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
def repair_empty_param_associations | |
params.keys.each do |key| | |
repair_nested_params(params, key, params[key]) | |
end | |
end | |
private | |
def repair_nested_params(current_params, key, value) | |
if key =~ /^(.*)_attributes$/ && value.nil? | |
current_params[key] = [] | |
elsif value.is_a? Hash | |
value.keys.each do |nested_key| | |
repair_nested_params(value, nested_key, value[nested_key]) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment