Skip to content

Commit 47aa3a5

Browse files
Alex TharpAlex Tharp
Alex Tharp
authored and
Alex Tharp
committed
Merge pull request #269 from cbdr/refactor-media-update_url-task
Refactor media:update_url Task
2 parents 0afdd47 + 71094dd commit 47aa3a5

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lib/tasks/cortex.rake

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,17 @@ namespace :cortex do
225225
begin
226226
s3.get_object({ bucket:ENV['S3_BUCKET_NAME'], key: object_key }, target: media.attachment_file_name)
227227

228-
file = File.new media.attachment_file_name
229-
230-
puts "Re-saving image attachment #{media.id} - #{media.attachment_file_name}"
231-
image = file
232-
media.attachment = image
233-
media.save
234-
# if there are multiple styles, you want to recreate them:
235-
media.attachment.reprocess!
236-
237-
file.close
238-
File.delete media.attachment_file_name
228+
image = Tempfile.new media.attachment_file_name
229+
begin
230+
puts "Re-saving image attachment #{media.id} - #{media.attachment_file_name}"
231+
media.attachment = image
232+
media.save
233+
# if there are multiple styles, you want to recreate them:
234+
media.attachment.reprocess!
235+
ensure
236+
image.close
237+
image.unlink
238+
end
239239
rescue => ex
240240
puts "An error of type #{ex.class} occurred, message is #{ex.message}"
241241
end

0 commit comments

Comments
 (0)