I have a model with a avatar
paperclip attach. It has now a plain standard path
has_attached_file :avatar,
:path => \"/:id-:style-:filename\"
<
If you want to work only with Paperclip and you are not worried about re-uploading I followed another approach.
Let's suppose you have the following:
class User
has_attached_file :image, path: "/:old_path/:filename"
...
end
and you want to migrate to the new path: "/:new_path/:filename"
my suggestion is to create a FakeUser
with the old path and change it in the User model.
class FakeUser
self.table_name = :users
has_attached_file :image, path: "/:old_path/:filename"
...
end
class User
has_attached_file :image, path: "/:new_path/:filename"
...
end
You can now write the following migration:
FakeUser.find_each do |fake_user|
User.find(fake_user.id).update(image: fake_user.image)
fake_user.image.destroy
end
You can then delete the FakeUser model when the migration is finished.
By the way, this approach will work perfectly also to migrate from local filesystem to S3 or vice-versa.