Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Repair Rails nested params
class ApplicationController < ActionController::Base
before_action :repair_nested_params
# -- your code here
protected
def repair_nested_params(obj = params)
obj.each do |key, value|
if value.is_a? Hash
# If any non-integer keys
if value.keys.find {|k, _| k =~ /\D/ }
repair_nested_params(value)
else
obj[key] = value.values
value.values.each {|h| repair_nested_params(h) }
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.