开发者

Paperclip Giving Required field error

开发者 https://www.devze.com 2023-02-15 06:15 出处:网络
in my project i have form in that there is file field to upload file and I am using paperclip gem for that and add only validation \'validates_attachment_content_type\' but when i submit a form withou

in my project i have form in that there is file field to upload file and I am using paperclip gem for that and add only validation 'validates_attachment_content_type' but when i submit a form without any file selected it gives error of 'validates_a开发者_JAVA百科ttachment_content_type', it should not give any error as i am not add validation 'validates_attachment_presence'. I am very confused for what it giving error of 'validates_attachment_content_type' when i submit a form without any file uploaded.


after googling for the same i got answer for this prob just we have to add :allow_nil => true in validation

for eg.

validates_attachment_content_type :logo, :content_type => ['image/jpeg','image/png','image /jpg','image/gif'], :message=>"Image file must be of .jpeg,'.jpg', '.gif' or .png type",:allow_nil => true


:allow_nil => true

is realy work great and very easy to test.YOu can put it after your validation.

0

精彩评论

暂无评论...
验证码 换一张
取 消