Explanation for validator of unique images added

This commit is contained in:
Christoph Haas 2015-04-27 00:54:57 +02:00
parent ca7065dd5c
commit 308c89c9ea

View file

@ -14,7 +14,9 @@ class Screenshot < ActiveRecord::Base
validates_with AttachmentSizeValidator, :attributes => :image, :less_than => 5.megabytes
validate :validate_image_is_unique
# Validator that checks if the image has already been uploaded
# Validator that checks if the image has already been uploaded.
# A generic uniqueness validator does not work because it would attribute
# the error to the :image_fingerprint field and not the actual :image field.
def validate_image_is_unique
# Look for images with the same checksum / image_fingerprint
if Screenshot.find_by(image_fingerprint: image_fingerprint)