metamaps--metamaps/app/models/attachment.rb

22 lines
442 B
Ruby
Raw Normal View History

2017-01-22 15:23:24 -05:00
class Attachment < ApplicationRecord
belongs_to :attachable, polymorphic: true
has_attached_file :file,
styles: lambda { |a|
a.instance.is_image? ? {
small: 'x200>',
medium: 'x300>',
large: 'x400>'
} : {}
}
validates_attachment_content_type :file, :content_type => [
/\Aimage\/.*\Z/,
/\Avideo\/.*\Z/
]
def is_image?
file.instance.file_content_type =~ %r(image)
end
end