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

前端 未结 3 720
迷失自我
迷失自我 2021-02-05 17:39

I\'ve got a rails model using Paperclip that looks like this:

  has_attached_file :image, :styles => { :normal => [\'857x392#\', :png] },
                          


        
3条回答
  •  -上瘾入骨i
    2021-02-05 18:02

    Paperclip's validation only checks the range, and doesn't care about the :allow_nil => true

    What you can do is try to set :min => nil or :min => -1, maybe that will work.

    Update: This will not work in the latest version of Paperclip since they have changed how validations work. What you could try instead is:

    validates_attachment_size :image, :less_than => 2.megabytes, 
       :unless => Proc.new {|model| model.image }
    

提交回复
热议问题