Added unique validator that checks for duplicate image uploads
This commit is contained in:
parent
9377af7795
commit
3a17af689e
1 changed files with 9 additions and 0 deletions
|
|
@ -12,6 +12,15 @@ class Screenshot < ActiveRecord::Base
|
||||||
url: '/screenshots/:id_partition/:style.png'
|
url: '/screenshots/:id_partition/:style.png'
|
||||||
validates_attachment_content_type :image, :content_type => 'image/png'
|
validates_attachment_content_type :image, :content_type => 'image/png'
|
||||||
validates_with AttachmentSizeValidator, :attributes => :image, :less_than => 5.megabytes
|
validates_with AttachmentSizeValidator, :attributes => :image, :less_than => 5.megabytes
|
||||||
|
validate :validate_image_is_unique
|
||||||
|
|
||||||
|
# Validator that checks if the image has already been uploaded
|
||||||
|
def validate_image_is_unique
|
||||||
|
# Look for images with the same checksum / image_fingerprint
|
||||||
|
if Screenshot.find_by(image_fingerprint: image_fingerprint)
|
||||||
|
errors.add(:image, "has already been uploaded")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Return caption for full-screen screenshots.
|
# Return caption for full-screen screenshots.
|
||||||
# Takes the description of a screenshot if available.
|
# Takes the description of a screenshot if available.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue