Created
July 25, 2012 10:49
-
-
Save darkleaf/3175516 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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