diff --git a/lib/paperclip.rb b/lib/paperclip.rb index e61d7c3..39ba262 100644 --- a/lib/paperclip.rb +++ b/lib/paperclip.rb @@ -220,7 +220,7 @@ module Paperclip attachment_definitions[name] = Attachment.build_class(name, options) const_set("#{name}_attachment".camelize, attachment_definitions[name]) - after_commit :save_attached_files + after_commit :save_attached_files, if: :persisted? after_commit :destroy_attached_files, on: :destroy after_commit :flush_attachment_jobs diff --git a/lib/paperclip/storage/no_cache_s3.rb b/lib/paperclip/storage/no_cache_s3.rb index e8d8653..e3e503e 100644 --- a/lib/paperclip/storage/no_cache_s3.rb +++ b/lib/paperclip/storage/no_cache_s3.rb @@ -134,7 +134,7 @@ module Paperclip def flush_writes # :nodoc: return if queued_for_write.empty? - + return if instance.destroyed? # если есть, что записывать (queued_for_write), значит, данные устарели instance[self.class.synced_field_name(self.class.main_store_id)] = false sync_to(self.class.main_store_id, queued_for_write) @@ -232,6 +232,7 @@ module Paperclip cache_control: "max-age=#{10.years.to_i}", acl: 'public-read' }.merge(self.class.upload_options) + files.each do |style, file| path = key(style) file.rewind