Skip to content

Instantly share code, notes, and snippets.

View romanlehnert's full-sized avatar

Roman Lehnert romanlehnert

  • Munich, Germany
View GitHub Profile
module Attributify
def attributify(key, unprocessed=params[key])
if unprocessed.is_a? Hash
specific_params = {}
unprocessed.each do |k,v|
if (v.is_a?(Hash) && !k.to_s.match(/_attributes$/)) or (v.is_a?(Array) && !k.to_s.match(/_ids$/))
# Nested, so suffix with '_attributes'
specific_params["#{k}_attributes".to_sym] = attributify(key, v)