Validation for uploaded image type added

This commit is contained in:
Christoph Haas 2020-08-17 01:47:59 +02:00
parent 3982cdb741
commit 53911f226d
3 changed files with 11 additions and 5 deletions

View file

@ -3,13 +3,12 @@ class Screenshot < ApplicationRecord
belongs_to :user, inverse_of: :screenshots
# Use paperclip gem to handle image files related to screenshots
# After migration from Paperclip to ActiveStorage:
has_one_attached :image
# has_attached_file :image,
# styles: { :large => '800x600>', :thumb => '160x120>' },
# default_url: '/images/dummy/no-screenshots-available.svg',
# path: ':rails_root/public/screenshots/:id_partition/:style.png',
# url: '/screenshots/:id_partition/:style.png'
# Validate using 'active_storage_validations' gem
validates :image, attached: true, content_type: { in: 'image/png', message: 'is not a valid PNG image file' }
#validates_attachment_content_type :image, :content_type => 'image/png'
#validates_with AttachmentSizeValidator, :attributes => :image, :less_than => 5.megabytes
# validate :validate_image_is_unique