Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 233
ground5hark Avatar asked Jan 11 '10 21:01

ground5hark


Video Answer


2 Answers

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

works now

like image 161
user1051870 Avatar answered Oct 21 '22 07:10

user1051870


validates_attachment_size :image, :less_than => 25.megabytes, 
                          :unless => Proc.new {|m| m[:image].nil?}

works perfectly for me

like image 38
Sytse Avatar answered Oct 21 '22 08:10

Sytse