Carrierwave – Recreate versions

Updated . Posted . Visible to the public.

A snippet of the carrierwave documentation Show archive.org snapshot

You might come to a situation where you want to retroactively change a version or add a new one. You can use the recreate_versions! method to recreate the versions from the base file. This uses a naive approach which will re-upload and process the specified version or all versions, if none is passed as an argument.

Call recreate_versions! on a mounted uploader.

A common usecase

User.all.each { |user| user.avatar.recreate_versions! if user.avatar? }

Caveats

  • recreate_versions! only processes :Symbol arguments. If you feed it strings, it will silently do nothing.
  • If your uploader dynamically generates the filename (e.g. by incorporating a user's name), you must call save afterwards, because recreate_versions! doesn't update the stored filename.
Martin Straub
Last edit
Arne Hartherz
Keywords
images, reprocess
License
Source code in this card is licensed under the MIT License.
Posted by Martin Straub to makandra dev (2013-10-23 09:15)