Resize or reprocess all Paperclip attachments

Update: This post was written based on an older version of paperclip which didn’t have a default rake task for this.

I’ve been using the Paperclip plugin/ gem for image attachment in several of my apps and I’ve encountered a scenario wherein I needed to change one of the styles configured in the model to accommodate the client’s request. At that point, there are already a bunch of images in the project so I need to resize or in Paperclip’s terms reprocess all of them to fit the new configuration.

Here’s how I did it:

If you have paperclip installed as a plugin

If Paperclip is installed as a plugin, you can do this:

rake paperclip:refresh:thumbnails CLASS=Attachment

Just replace Attachment with whatever classname you are using for with Paperclip

If it’s installed as a gem, do this inside script/console:

Attachment.all.each {|s| s.logo.reprocess! if s.logo}

Just replace Attachment with whatever class name you are using for with Paperclip and logo with whatever attribute name you are using for the image.

And you’re done 🙂

2 Comments

  1. I installed paperclip as a gem and rake -T tells me that i have paperclip:refresh:thumbnails task available.

Leave a Reply

Your email address will not be published. Required fields are marked *