Sha256: b9e67a90d04ae11755163aa456979a4d00b36ff139de46c69dbc36848cd9dcbe
Contents?: true
Size: 976 Bytes
Versions: 2
Compression:
Stored size: 976 Bytes
Contents
class CmsUpload < ActiveRecord::Base # -- AR Extensions -------------------------------------------------------- has_attached_file :file, :styles => { :thumb => '48x48>' } before_post_process :image? # -- Relationships -------------------------------------------------------- belongs_to :cms_page # -- Validations ---------------------------------------------------------- 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 if self.image? self.file.url(:thumb) else ext = self.file_file_name.split('.').last FILE_ICONS.include?(ext) ? "cms/file_icons/#{ext}.png" : "cms/file_icons/_blank.png" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
comfortable_mexican_sofa-1.0.1 | app/models/cms_upload.rb |
comfortable_mexican_sofa-1.0.0 | app/models/cms_upload.rb |