diff --git a/app/models/brochure.rb b/app/models/brochure.rb index 2efc3035..b60dee60 100644 --- a/app/models/brochure.rb +++ b/app/models/brochure.rb @@ -12,4 +12,6 @@ class Brochure < ApplicationRecord has_one_attached :image, dependent: :destroy has_one_attached :pdf, dependent: :destroy + validates :image, presence: false, + blob: { content_type: Imageable::ALLOWED_IMAGE_TYPES, size_range: Imageable::IMAGE_SIZE_RANGE } end diff --git a/app/models/catalog.rb b/app/models/catalog.rb index 9fa5977f..a623e2dc 100644 --- a/app/models/catalog.rb +++ b/app/models/catalog.rb @@ -14,6 +14,8 @@ class Catalog < ApplicationRecord has_many :books, primary_key: :code, class_name: "Book", dependent: :nullify has_one_attached :pdf, dependent: :destroy has_one_attached :image, dependent: :destroy + validates :image, presence: false, + blob: { content_type: Imageable::ALLOWED_IMAGE_TYPES, size_range: Imageable::IMAGE_SIZE_RANGE } def set_title if code.present? diff --git a/app/models/concerns/imageable.rb b/app/models/concerns/imageable.rb index 9241c2bc..f5120d1c 100644 --- a/app/models/concerns/imageable.rb +++ b/app/models/concerns/imageable.rb @@ -3,6 +3,9 @@ module Imageable extend ActiveSupport::Concern + ALLOWED_IMAGE_TYPES = %w[image/png image/jpg image/jpeg image/gif].freeze + IMAGE_SIZE_RANGE = 1..5.megabytes + def thumb_image(image_field) custom_image(image_field, 160, 220) end diff --git a/app/models/event.rb b/app/models/event.rb index cd0a04c5..efbb8112 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -5,6 +5,8 @@ class Event < ApplicationRecord include Imageable validates :title, :start_date, :end_date, presence: true + validates :image, presence: false, + blob: { content_type: Imageable::ALLOWED_IMAGE_TYPES, size_range: Imageable::IMAGE_SIZE_RANGE } has_rich_text :description has_rich_text :news_text diff --git a/app/models/highlight.rb b/app/models/highlight.rb index 4f5aaa56..8cc2eb50 100644 --- a/app/models/highlight.rb +++ b/app/models/highlight.rb @@ -5,6 +5,8 @@ class Highlight < ApplicationRecord include Friendable validates :title, :image, :link, :alt_text, presence: true + validates :image, presence: false, + blob: { content_type: Imageable::ALLOWED_IMAGE_TYPES, size_range: Imageable::IMAGE_SIZE_RANGE } has_one_attached :image end diff --git a/app/models/news_item.rb b/app/models/news_item.rb index a30bb042..d7d16279 100644 --- a/app/models/news_item.rb +++ b/app/models/news_item.rb @@ -5,6 +5,8 @@ class NewsItem < ApplicationRecord include Friendable validates :title, :image, presence: true + validates :image, presence: false, + blob: { content_type: Imageable::ALLOWED_IMAGE_TYPES, size_range: Imageable::IMAGE_SIZE_RANGE } has_one_attached :image has_rich_text :description