Skip to content

Instantly share code, notes, and snippets.

@palkan
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palkan/a81679d004737df87fed to your computer and use it in GitHub Desktop.
Save palkan/a81679d004737df87fed to your computer and use it in GitHub Desktop.
"Restore" S3 assets after updating Paperclip hash_data
# Suppose we updated our hash_data for Paperclip
OLD_HASH = ":class/:attachment/:id/:style"
NEW_HASH = ":class/:attachment/:id/:style/:updated_at"
ACL = :public_read
def restore(r)
return unless r.file.exists?
new_key = r.file.path[1..-1]
r.file.options[:hash_data] = OLD_HASH;
old_key = r.file.path[1..-1]
o = bucket.objects[old_key];
if o.exists?
o.move_to(new_key, acl: ACL)
else
p "Doesn't exist: #{old_key}"
end
r.file.options[:hash_data] = NEW_HASH;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment