Carrierwave – Recreate versions

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.
Over 10 years ago