【发布时间】:2010-07-05 19:56:58
【问题描述】:
是否可以在paperclip 中强制执行“内容类型”验证而不强制执行“存在”验证(即允许空白)?我目前有:
class Person < ActiveRecord::Base
has_attached_file :picture
validates_attachment_content_type :picture, :content_type => ['image/jpeg', 'image/jpg', 'image/png']
end
但是,如果不存在附件,则此操作会失败。例如:
>> @person = Person.new
>> @person.save
>> @person.errors.first
=> ["picture_content_type", "is not one of image/jpeg, image/jpg, image/png"]
是否可以仅在包含附件时进行验证。
【问题讨论】: