Rails - Paperclip validating attachment size when it shouldn't be?

ground5hark picture ground5hark · Jan 11, 2010 · Viewed 15.6k times · Source

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?

Answer

user1051870 picture user1051870 · Aug 30, 2012

validates_attachment_size :image, :in => 0.megabytes..2.megabytes

works now