Last active
July 22, 2019 22:06
-
-
Save Hamada92/b014dc95ef2e26fe52cecb599395d1f2 to your computer and use it in GitHub Desktop.
how to create new avatar names
This file contains 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
# open AvatarUploader and re-define the filename method dynamically- because ewe can't deploy this code, | |
# it doesn't work for new records as the processing happens async and can't gauarentee that model.id exists, so we | |
# should run it only after the record is created. | |
AvatarUploader.class_eval do | |
def filename | |
token = OpenSSL::HMAC.hexdigest('SHA256', ENV['AWS_SECRET'], model.id.to_s) | |
"#{token}.#{file.extension}" | |
end | |
end | |
# backfill | |
Account.find_each do |account| | |
account.image.recreate_versions! # a carrierwave method | |
account.save! | |
end | |
# then we can schedule that as a daily task to backfill the new accounts that are created everyday. Can also use a new | |
# column :obfuscated and set to true when done. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ed
I'd go with this, except that it would cause data redundancy, because the name will be stored in
image
field as well. A boolean is cleaner in this case I think.