lib/tasks/paperclip.rake in paperclip-2.4.3 vs lib/tasks/paperclip.rake in paperclip-2.4.4
- old
+ new
@@ -71,26 +71,30 @@
ENV['CLASS'] = klass.to_s
ENV['ATTACHMENT'] = attachment_name.to_s
ENV['STYLES'] = missing_styles.join(',')
Rake::Task['paperclip:refresh:thumbnails'].execute
end
- end
+ end
Paperclip.save_current_attachments_styles!
end
end
desc "Cleans out invalid attachments. Useful after you've added new validations."
task :clean => :environment do
klass = Paperclip::Task.obtain_class
names = Paperclip::Task.obtain_attachments(klass)
names.each do |name|
Paperclip.each_instance_with_attachment(klass, name) do |instance|
- instance.send(name).send(:validate)
- if instance.send(name).valid?
- true
- else
- instance.send("#{name}=", nil)
- instance.save
+ unless instance.valid?
+ attributes = %w(file_size file_name content_type).map{ |suffix| "#{name}_#{suffix}".to_sym }
+ if attributes.any?{ |attribute| instance.errors[attribute].present? }
+ instance.send("#{name}=", nil)
+ if Rails.version >= "3.0.0"
+ instance.save(:validate => false)
+ else
+ instance.save(false)
+ end
+ end
end
end
end
end
end