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

前端 未结 3 708
迷失自我
迷失自我 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条回答
  • 2021-02-05 18:01

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

    works now

    0 讨论(0)
  • 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 }
    
    0 讨论(0)
  • 2021-02-05 18:07
    validates_attachment_size :image, :less_than => 25.megabytes, 
                              :unless => Proc.new {|m| m[:image].nil?}
    

    works perfectly for me

    0 讨论(0)
提交回复
热议问题