Scenario: A post object has multiple image attachments. When a new post is added, image attachments are also uploaded via the same data entry form.
Problem:
Assume that 5 files were browsed and selected for uploading. Out of those 5, 3 of them were non-image files (ie. pdf, word).
Prior to rails 3 and paperclip 3.x.x:
In the past with my other application that was on rails 2.3.8 and paperclip 2.x.x, I used to do the following and it worked beautifully.
validate :image, :check_content_type
def check_content_type
if !['image/jpg', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/gif', 'image/png'].include?(self.image_content_type)
errors.add( 'attachment,', "'#{self.image_file_name}' is not a valid image type")
end
end
Currently:
In rails 3 and paperclip 3.0.3, there is only 1 generic error message being passed back and it's not very correct.
For an attachment model that has_many :images, the error message will read 'Images image content type is invalid'.
Can anyone please show me how to have custom error messages defined for each invalid attachment? Of course, the error message must show the file name of the invalid attachment so that the user knows which file is at fault.