metamaps--metamaps/app/models/attachment.rb
Devin Howard 696ff396b0 file attachments in db (re: #124) (#1043)
* file attachments in db

* rubocop

* factor out a bunch of file types

* thumb and medium image styles"

* syntax error in concern

* markdown is also plaintext

* rubocop
2017-01-24 15:10:40 -05:00

38 lines
939 B
Ruby

# frozen_string_literal: true
class Attachment < ApplicationRecord
belongs_to :attachable, polymorphic: true
has_attached_file :file,
styles: lambda { |a|
if a.instance.image?
{
thumb: 'x128#',
medium: 'x320>'
}
else
{}
end
}
validates_attachment_content_type :file, content_type: Attachable.allowed_types
def image?
Attachable.image_types.include?(file.instance.file_content_type)
end
def audio?
Attachable.audio_types.include?(file.instance.file_content_type)
end
def text?
Attachable.text_types.include?(file.instance.file_content_type)
end
def pdf?
Attachable.pdf_types.include?(file.instance.file_content_type)
end
def document?
text? || pdf?
end
end