Skip to content

Instantly share code, notes, and snippets.

@maslenkov
Created December 19, 2014 15:13
Show Gist options
  • Save maslenkov/397b483ade52082984b5 to your computer and use it in GitHub Desktop.
Save maslenkov/397b483ade52082984b5 to your computer and use it in GitHub Desktop.
rake task to recreate all image versions in rails project with carrierwave
...
gem 'ruby-progressbar'
...
namespace :images do
desc 'recreate versions for all images'
task recreate_versions: :environment do
# recreator MODEL_NAME, FIELD1 # , [...]
recreator Image, 'file'
recreator Project, 'photo', 'landing_photo'
end
end
def recreator(klass, *image_fields)
pb = ProgressBar.create(title: klass.name, total: klass.count, format: '%t: [%B] %c/%C %e %a')
klass.all.each do |image_owner|
image_fields.each do |image_field|
image = image_owner.send(image_field)
image.recreate_versions! if image.present?
end
pb.increment
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment