Commit 28d84d70
Changed files (2)
app
models
app/models/creation.rb
@@ -28,14 +28,6 @@ class Creation < ActiveRecord::Base
end
end
- def migrate_primary_image
- photo = photos.build({})
- photo.created_at = created_at
- photo.updated_at = updated_at
- photo.image = image.file
- photo.save!
- end
-
def published?
photos.count > 0
end
db/migrate/20121010190225_migrate_images_for_each_creation.rb
@@ -1,9 +1,19 @@
+class MigratePrimaryImage < Struct.new(:creation_id)
+ def perform
+ creation = Creation.find(creation_id)
+ photo = creation.photos.build({})
+ photo.created_at = creation.created_at
+ photo.updated_at = creation.updated_at
+ photo.image = creation.image.file
+ photo.save!
+ end
+end
+
class MigrateImagesForEachCreation < ActiveRecord::Migration
def up
Creation.all.each_with_index do |creation, index|
- creation.delay.migrate_primary_image
+ Delayed::Job.enqueue MigratePrimaryImage.new(creation.id)
end
- #remove_column :creations, :image
end
def down