Navigation Menu

Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Errors on presence get added to :attachment and :attachment_file_name
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed Oct 20, 2011
1 parent 61a0536 commit cd53485
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/paperclip.rb
Expand Up @@ -390,7 +390,10 @@ def validates_attachment_presence name, options = {}
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)
record.errors.add(name, message) if if_clause_passed && unless_clause_passed && value.blank?
if if_clause_passed && unless_clause_passed && value.blank?
record.errors.add(name, message)
record.errors.add("#{name}_file_name", message)
end
end
end

Expand Down
1 change: 1 addition & 0 deletions test/paperclip_test.rb
Expand Up @@ -225,6 +225,7 @@ def self.should_validate validation, options, valid_file, invalid_file
end
if validation == :presence
should "have an error on the attachment" do
assert @dummy.errors[:avatar]
assert @dummy.errors[:avatar_file_name]
end
else
Expand Down

0 comments on commit cd53485

Please sign in to comment.