Paperclip允许用户上传800x500及以上的图片 Rails 4

Paperclip allow users to upload pictures of 800x500 and above in Rails 4

我在我的模型中创建了一个名为 dimensions_validator.rb

的文件标题
class DimensionsValidator < ActiveModel::EachValidator


    def validate_each(record, attribute, value)
        if record.send("#{attribute}?".to_sym)
          dimensions = Paperclip::Geometry.from_file(value.queued_for_write[:original].path)
          width = options[:width]
          height = options[:height]

          record.errors[attribute] << "Width must be at least #{width}px" unless dimensions.width = width
          record.errors[attribute] << "Height must be at least #{height}px" unless dimensions.height = height
        end
      end
    end

在我的 产品 模型中,我

validates :image, dimensions: { width: 800, height: 500 }

Question: How can allow users to upload pictures of 800x500 and above?

只需替换这些行中的条件和消息:

record.errors[attribute] << "Width must be at least #{width}px" if dimensions.width < width
record.errors[attribute] << "Height must be at least #{height}px" if dimensions.height < height