Guest User

Untitled

a guest
Oct 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. class ApplicationController < ActionController::Base
  2. before_filter :repair_nested_params
  3.  
  4. protected
  5.  
  6. # Fixes nested attribute params for strong_parameters (turns string keyed hash
  7. # into array of hashes)
  8. def repair_nested_params(obj = params)
  9. obj.each do |key, value|
  10. if value.is_a? Hash
  11. # If any non-integer keys
  12. if value.keys.find {|k, _| k =~ /\D/ }
  13. repair_nested_params(value)
  14. else
  15. obj[key] = value.values
  16. value.values.each {|h| repair_nested_params(h) }
  17. end
  18. end
  19. end
  20. end
  21. end
Add Comment
Please, Sign In to add comment