Sha256: 6e4974a831c523206979a689cb2350f87df6f7265e5ba7b594237e407853db68

Contents?: true

Size: 871 Bytes

Versions: 26

Compression:

Stored size: 871 Bytes

Contents

class CmsUpload < ActiveRecord::Base

  # -- AR Extensions --------------------------------------------------------
  has_attached_file :file,
    :styles => { :thumb => '48x48>' }
  
  before_post_process :image?
  
  # -- Relationships --------------------------------------------------------
  belongs_to :cms_site
  
  # -- Validations ----------------------------------------------------------
  validates :cms_site_id,
    :presence   => true
  validates_attachment_presence :file 
  
  # -- Instance Methods -----------------------------------------------------
  def image?
    !(file_content_type =~ /^image.*/).nil?
  end
  
  def uploaded_file=(data)
    if data.present?
      data.content_type = MIME::Types.type_for(data.original_filename).to_s
      self.file = data
    end
  end
  
  def icon
    self.image?? self.file.url(:thumb) : 'TODO'
  end
  
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.0.28 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.27 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.26 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.25 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.24 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.23 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.22 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.21 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.20 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.19 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.18 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.17 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.16 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.15 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.14 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.13 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.12 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.11 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.10 app/models/cms_upload.rb
comfortable_mexican_sofa-1.0.9 app/models/cms_upload.rb