lib/paperclip.rb in paperclip-2.4.4 vs lib/paperclip.rb in paperclip-2.4.5

- old
+ new

@@ -385,13 +385,17 @@ # * +if+: A lambda or name of a method on the instance. Validation will only # be run is this lambda or method returns true. # * +unless+: Same as +if+ but validates if lambda or method returns false. def validates_attachment_presence name, options = {} message = options[:message] || :empty - validates_presence_of :"#{name}_file_name", - :message => message, - :if => options[:if], - :unless => options[:unless] + validates_each :"#{name}_file_name" do |record, attr, value| + if_clause_passed = options[:if].nil? || (options[:if].call(record) != false) + unless_clause_passed = options[:unless].nil? || (!!options[:unless].call(record) == false) + if if_clause_passed && unless_clause_passed && value.blank? + record.errors.add(name, message) + record.errors.add("#{name}_file_name", message) + end + end end # Places ActiveRecord-style validations on the content type of the file # assigned. The possible options are: # * +content_type+: Allowed content types. Can be a single content type