Skip to content

Instantly share code, notes, and snippets.

@rjswenson
Created August 27, 2015 21:56
Show Gist options
  • Save rjswenson/6087dbc1ed5871337c2b to your computer and use it in GitHub Desktop.
Save rjswenson/6087dbc1ed5871337c2b to your computer and use it in GitHub Desktop.
Mongoid nested_dup
def nested_dup
dup_dash_hash = self.dup.as_document
children_hash.each do |key, child_object|
dup_dash_hash["#{key.to_s}_attributes"] = child_object.dup.as_document
end
new_dash = Dashboard::Component::Wrapper.new(dup_dash_hash)
new_dash.carousel.items.map {|it| it.image.reprocess! }
new_dash.content_ribbon.items.map {|it| it.image.reprocess! }
new_dash.save(validate: false)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment