How to write a script (in Ruby / Rails) that will restore all thumbnails for my new clip styles?

I have an image model with the following two styles:

:original => ['500x400!'], :thumb => ['75x54!',:jpg] 

Latest style :: thumb, I just resized to make thubnails bigger.

This works great for new images uploaded by users, but I'm not sure how to have a paperclip loop through all my existing thumbnails and resize them.

Hoping someone can give some advice on how to do this.

Thanks!

+4
source share
2 answers

There is a rake task for this:

 rake paperclip:refresh:thumbnails CLASS=YourModel 

To have more control, you can also manually redraw thumbnails for specific instances:

 some_model_instances.each do |instance| instance.photo.reprocess! end 
+7
source

A paper clip comes with a rake task that does just that:

 rake paperclip:refresh RAILS_ENV=production CLASS=Photo 

In this example, the above will generate all attachments belonging to the Photo class.

+4
source

Source: https://habr.com/ru/post/1342936/


All Articles