I've got a rails model using Paperclip that looks like this:
has_attached_file :image, :styles => { :normal => ['857x392#', :png] },
:url => '/assets/pages/:id/:basename.:extension',
:path => ':rails_root/public/assets/pages/:id/:basename.:extension'
validates_attachment_size :image, :less_than => 2.megabytes
When attempting to create a record of this model without an attachment to upload, the validation error is returned:
There were problems with the following fields:
* Image file size file size must be between 0 and 2097152 bytes.
I've tried passing both :allow_blank => true and :allow_nil => true after the validation statement in the model, but neither have worked.
How can I allow the :image parameter to be blank?
validates_attachment_size :image, :in => 0.megabytes..2.megabytes
works now
validates_attachment_size :image, :less_than => 25.megabytes,
:unless => Proc.new {|m| m[:image].nil?}
works perfectly for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With