Extract constant to configure valid mime types

This way it'll be possible to overwrite the valid mime types in a custom
model.
This commit is contained in:
Javi Martín
2022-08-03 15:49:22 +02:00
parent 00ea1bf719
commit 11bed74678
2 changed files with 17 additions and 1 deletions

View File

@@ -11,10 +11,12 @@ class SiteCustomization::Image < ApplicationRecord
"logo_email" => [400, 80]
}.freeze
VALID_MIME_TYPES = %w[image/jpeg image/png].freeze
has_attachment :image
validates :name, presence: true, uniqueness: true, inclusion: { in: ->(*) { VALID_IMAGES.keys }}
validates :image, file_content_type: { allow: ["image/png", "image/jpeg"], if: -> { image.attached? }}
validates :image, file_content_type: { allow: ->(*) { VALID_MIME_TYPES }, if: -> { image.attached? }}
validate :check_image
def self.all_images