artimys
4/14/2017 - 6:38 PM

CarrierWave

# create a specific version
ProductImage.find(46).image.recreate_versions!(:xs)

# check if version exists
# ProductImage.find(46).<uploader>.<version>.file.exists?
ProductImage.find(46).image.xs.file.exists?


	task :xs => :environment do
		begin

			img_count = 0

			ProductImage.all.find_each(batch_size: 500) do |product_image|

				img_count += 1

				if product_image.image.xs.file.exists?
					puts "Exists: #{product_image.id}"
				else
					# Doesn't exist, create version
					product_image.image.recreate_versions!(:xs)
					puts "Added: #{product_image.id}"
				end

			end


			puts "Total ProductImage count: #{img_count}"

		rescue Exception => e
			puts "Exception: #{e}"
		end
	end