Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 22 lines (21 sloc) 0.646 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
namespace :images do
  desc "Regenerate images"
  task :regenerate => :environment do
    require 'open-uri'
    OpportunityPhoto.all.each do |photo|
      begin
        old_name = photo.image_file_name
        new_image = open(photo.image.url(:original, escape: false))
        class << new_image
          def original_filename; @original_filename; end
          def original_filename=(name); @original_filename = name; end
        end
        new_image.original_filename = old_name
        photo.image = new_image
        photo.save
      rescue => e
        puts "ERROR: #{e.message} while processing #{photo.id}"
      end
    end
  end
end
Something went wrong with that request. Please try again.