Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ApplicationController < ActionController::Base
- before_filter :repair_nested_params
- protected
- # Fixes nested attribute params for strong_parameters (turns string keyed hash
- # into array of hashes)
- 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
Add Comment
Please, Sign In to add comment