8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb', line 8
def self.generate_delete_helper(klass, field)
klass.class_eval <<-CODE, __FILE__, __LINE__ + 1 unless klass.method_defined?(:"delete_#{field}=")
attr_reader :delete_#{field} # attr_reader :delete_file
#
def delete_#{field}=(value) # def delete_file=(value)
value = (value == "true") if String === value # value = (value == "true") if String === value
return unless value # return unless value
#
# passing nil to the file column causes the file # # passing nil to the file column causes the file
# to be deleted. Don't delete if we just uploaded a file! # # to be deleted. Don't delete if we just uploaded a file!
self.#{field} = nil unless self.#{field}.dirty? # self.file = nil unless self.file.dirty?
end # end
CODE
end
|