Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/attachinary/orm/active_record/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def attachinary_orm_definition(options)
define_method "#{options[:scope]}=" do |input, upload_options = {}|
input = Attachinary::Utils.process_input(input, upload_options, options[:scope])
if input.nil?
send("#{relation}").clear
send("#{relation}").destroy_all
else
files = [input].flatten
send("#{relation}=", files)
Expand Down
8 changes: 7 additions & 1 deletion lib/attachinary/orm/file_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ def self.included(base)
if Rails::VERSION::MAJOR == 3
base.attr_accessible :public_id, :version, :width, :height, :format, :resource_type
end
base.after_destroy :destroy_file
base.after_create :remove_temporary_tag
# In AR remote file deletion will be performed after transaction is committed
if base.respond_to?(:after_commit)
base.after_commit :destroy_file, on: :destroy
else
# Mongoid does not support after_commit
base.after_destroy :destroy_file
end
end

def as_json(options)
Expand Down