Created
December 19, 2014 15:13
-
-
Save maslenkov/397b483ade52082984b5 to your computer and use it in GitHub Desktop.
rake task to recreate all image versions in rails project with carrierwave
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
gem 'ruby-progressbar' | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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