-
-
Save romanlehnert/debda25c4d1d5416cc0c to your computer and use it in GitHub Desktop.
This file contains 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
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) | |
else | |
specific_params[k] = v | |
end | |
end | |
return specific_params | |
elsif unprocessed.is_a? Array | |
unprocessed.map do |p| attributify(key, p) end | |
else | |
unprocessed | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment