Recently, In Paperclip (4.1.1) I had to change the hash_secret, which is used for the purpose of URI Obfuscation. But, the problem was that there had been many files in production generated with the old hash_secret. Simply just changing the hash_secret would invalidate all the old URL’s as paperclip does not store the URL’s of the files instead it generates using the path option given to it (which would obviously contain the :hash interpolation).
It was evident that I had to write a migration to move the already existing files from old location to new location (We were storing the files in S3). Also, I wanted the moving part to simply look like
In order for file.old_path to work I had to override Paperclip::Attachment and add old_path method to it. Although, it turned out that I had to override three more functions, it was worth it. Besides, this override was just a temporary one.
Here is the rake task which moves the file from old location to the new location just as I wanted it to be,
If you are using a File Storage, then you could find appropriate ruby code to move file from one path to another on Google.