Is it possible to enforce a \'content type\' validation in paperclip without enforcing a \'presence\' validation (i.e. allow blanks)? I currently have:
class
In the following model only image/png, image/gif and image/jpeg are valid content types for the image attachment.
class Photo
has_attached_file :image
validates_attachment_content_type :image,
:content_type => /^image\/(png|gif|jpeg)/
end
describe Photo do
it { should validate_attachment_content_type(:image).
allowing('image/png', 'image/gif', 'image/jpeg').
rejecting('text/plain', 'text/xml', 'image/abc', 'some_image/png') }
end
You could also take a look at the AttachmentContentTypeValidator class with is responsible for doing the validation.
Or take a look at its tests which contain more examples.