Sha256: d946ed36f127508ab057dc72ee660d2222a4b1ac286c83d635868a555aadb907
Contents?: true
Size: 1.31 KB
Versions: 1
Compression:
Stored size: 1.31 KB
Contents
# frozen_string_literal: true module Decidim # Attachment can be any type of document or images related to a partcipatory # process. class Attachment < ApplicationRecord belongs_to :attached_to, polymorphic: true validates :file, :attached_to, :content_type, presence: true validates :file, file_size: { less_than_or_equal_to: ->(_attachment) { Decidim.maximum_attachment_size } } mount_uploader :file, Decidim::AttachmentUploader # Whether this attachment is a photo or not. # # Returns Boolean. def photo? @photo ||= content_type.start_with? "image" end # Whether this attachment is a document or not. # # Returns Boolean. def document? !photo? end # Which kind of file this is. # # Returns String. def file_type file.url&.split(".")&.last&.downcase end # The URL to download the file. # # Returns String. def url file.url end # The URL to download the thumbnail of the file. Only works with images. # # Returns String. def thumbnail_url return unless photo? file.thumbnail.url end # The URL to download the a big version of the file. Only works with images. # # Returns String. def big_url return unless photo? file.big.url end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
decidim-core-0.2.0 | app/models/decidim/attachment.rb |