Can not run 'rake paperclip:refresh:thumbnails CLASS=Spree::Image' in rails spree app console getting No Such Key

假装没事ソ 提交于 2019-12-04 16:23:45

Ok so I wrote this question to answer it myself. I hope the question makes sense.

For clarity, I had this issue because it was old images (old non existing paths that were associated with an old S3 Key) that I had uploaded with another S3 Key in previous testing on the same rails app. I did this earlier while trying to get S3 to work with my Rails Spree Application.

What I did to solve this was go into my Rails console on my remote server with this command:

$RAILS_ENV=production rails c

I then ordered the list of all Spree:Images them with this:

$y Spree::Image.all(:order => 'attachment_updated_at')

The 'y' is a nice little yaml way of displaying the information of the Spree:Image that's a little more human.

Next I looked at the ID of each Image and noticed that there was a good amount of them with IDs that did not match folders in my AWS S3 bucket.

In my Case the lowest ID number that was in fact a folder in my S3 bucket was '1078' so I ran this:

$Spree::Image.where('id < ?', 1078).destroy_all

This deleted any Spree::Image that had an ID of 1077 or less.

Finally, I closed rails console and ran this on my remote server inside my current rails app directory. (In my case is was /home/deployer/apps/potentialapp/current/)

$RAILS_ENV=production rake paperclip:refresh:thumbnails CLASS=Spree::Image

This reformatted my uploaded images on Spree and everything is now working great.

Hope this saves someone a great big headache. (Oh and empty your cache when you go to test and see if the images have in fact reloaded, almost cried at 4 am last night.)

I solved the same problem using the console and skipping errors (old/broken S3 assets):

Spree::Image.all.each { |i| i.attachment.reprocess! rescue nil }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!