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