Skip to content

Instantly share code, notes, and snippets.

@paderinandrey
Created January 30, 2017 12:52
Show Gist options
  • Save paderinandrey/f77c12ab75dc57d203317175a4b326ca to your computer and use it in GitHub Desktop.
Save paderinandrey/f77c12ab75dc57d203317175a4b326ca to your computer and use it in GitHub Desktop.
class CloneCourse < ActiveJob::Base
def perform(course)
ActiveRecord::Base.transaction do
@new_course = course.dup
@new_course.save!
course.materials.each do |material|
@new_material = material.dup
@new_material.course = @new_course
@new_material.save!
copy_file(material, @new_material)
end
end
end
private
def copy_file(material, new_material)
s3 = AWS::S3.new(material.file.s3_credentials)
s3_file = s3.buckets[material.file.s3_credentials[:bucket]].objects.first
s3_file.copy_to(new_material.file.s3_object)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment