Sha256: 356475ad389559d05e6173f438195ab68d1f499e06f298a0f1d8f62f39c6d23a
Contents?: true
Size: 874 Bytes
Versions: 4
Compression:
Stored size: 874 Bytes
Contents
require 'carrierwave' require 'carrierwave/orm/activerecord' class Resource < ActiveRecord::Base belongs_to :blog belongs_to :article mount_uploader :upload, ResourceUploader validate :image_mime_type_consistent validates :upload, presence: true scope :without_images, -> { where("mime NOT LIKE '%image%'") } scope :images, -> { where("mime LIKE '%image%'") } scope :by_filename, -> { order('upload') } scope :by_created_at, -> { order('created_at DESC') } scope :without_images_by_filename, -> { without_images.by_filename } scope :images_by_created_at, -> { images.by_created_at } private def image_mime_type_consistent if upload.content_type =~ %r{^image/} expected_type = upload.file.send :mime_magic_content_type errors.add(:upload, 'Has MIME type mismatch') unless upload.content_type == expected_type end end end
Version data entries
4 entries across 4 versions & 1 rubygems