It may not be the same at all, but for googleability:
We have a random hash in the file name, similar to what is described in this discussion thread .
When restoring images, it will generate new images using the new hash, but it will not update the file name stored in the database, so it will try to display the images with the old names.
This reproduces the problem:
bundle exec rails runner "Foo.find(123).images.each { |img| uploader = img.image; puts %{before: #{img.image.inspect}}; uploader.recreate_versions!; puts %{after: #{img.reload.image.inspect}} }; p Foo.find(123).images"
It gives a conclusion, for example
before: /uploads/foo_123_6a34e47ef5.JPG after: /uploads/foo_123_d9a346292d.JPG [#<Image id: 456, foo_id: 123, image: "foo_123_6a34e47ef5.JPG">]
But the addition of img.save! after reconstituting the versions fixes it:
bundle exec rails runner "Foo.find(123).images.each { |img| uploader = img.image; puts %{before: #{img.image.inspect}}; uploader.recreate_versions!; img.save!; puts %{after: #{img.reload.image.inspect}} }; p Foo.find(123).images"
With an exit:
before: /uploads/foo_123_6a34e47ef5.JPG after: /uploads/foo_123_d9a346292d.JPG [#<Image id: 456, foo_id: 123, image: "foo_123_d9a346292d.JPG">]
Edit:
Actually, the above worked with files on the disk, but not with fog. To make everything easy for myself, I ended up just recreating the images and deleting the old ones:
Image.all.each { |old| new = Image.new(foo_id: old.foo_id, image: old.image) new.save! old.destroy }