Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/brochure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions app/models/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
3 changes: 3 additions & 0 deletions app/models/concerns/imageable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/models/highlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions app/models/news_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down