Skip to content

Instantly share code, notes, and snippets.

@raymyers
Created July 29, 2009 19:41
Show Gist options
  • Save raymyers/158352 to your computer and use it in GitHub Desktop.
Save raymyers/158352 to your computer and use it in GitHub Desktop.
def deep_attributes
attributes_to_copy(self).merge 'service_appointments_attributes'=>service_appointments.collect{|sa|
attributes_to_copy(sa).merge 'student_appointments_attributes'=>sa.student_appointments.collect{|std_a|
attributes_to_copy(std_a).merge 'student_appointment_goals_attributes'=>std_a.student_appointment_goals.collect{|sag|
attributes_to_copy(sag)
}
}
}
end
private
def attributes_to_copy(ar)
forbidden_keys = ['id', 'service_transaction_id', 'service_appointment_id', 'student_appointment_id']
ar.attributes.reject do |k,v|
forbidden_keys.index(k)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment