Use file_validators instead of Papeclip validations

Since we're going to remove Paperclip and Active Storage doesn't provide
any validations, we have to either write our own validation rules or use
a different gem.

We're using the file_validators gem instead of the
`active_storage_validations` gem because the latter doesn't support
proc/lambda objects in size and content type definitions. We need to use
them because in our case these values depend on settings stored in the
database.
This commit is contained in:
Javi Martín
2021-07-27 23:50:43 +02:00
parent 7daf75d01a
commit 600f5c35e9
7 changed files with 22 additions and 4 deletions

View File

@@ -14,7 +14,9 @@ class SiteCustomization::Image < ApplicationRecord
has_attachment :image
validates :name, presence: true, uniqueness: true, inclusion: { in: VALID_IMAGES.keys }
validates_attachment_content_type :image, content_type: ["image/png", "image/jpeg"]
do_not_validate_attachment_file_type :image
validates :image, file_content_type: { allow: ["image/png", "image/jpeg"] }
validate :check_image
def self.all_images