Skip to content

Instantly share code, notes, and snippets.

@darkleaf
Created July 25, 2012 10:49
Show Gist options
  • Save darkleaf/3175516 to your computer and use it in GitHub Desktop.
Save darkleaf/3175516 to your computer and use it in GitHub Desktop.
require File.expand_path("../../config/environment", __FILE__)
OLD_BASE_DIR = "public/system/uploads/object_model"
FALLBACK_PATH = "/images/fallback/default.png"
def copy(model, mounter_name)
mounter = model.public_send(mounter_name)
if mounter.to_s != FALLBACK_PATH
basename = File.basename mounter.to_s
return if basename =~ /#{mounter_name.to_s}\./
old_path = [OLD_BASE_DIR, mounter_name.to_s, model.id, basename].join '/'
old_file = File.open(old_path)
model.public_send(:"#{mounter_name}=", old_file)
end
end
ObjectModel.find_each do |o|
copy o, :stack_image
copy o, :short_info_image
o.save!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment