Sha256: 327bf6182824b21efaca5144894869903a5b5c58e4d0e5ff27511f0a98500b14
Contents?: true
Size: 1.35 KB
Versions: 1
Compression:
Stored size: 1.35 KB
Contents
class Document < ActiveRecord::Base include SocialStream::Models::Object IMAGE_FORMATS = ["doc","ppt","xls","rar","zip","mpeg","plain","pdf"] has_attached_file :file, :url => '/:class/:id.:extension', :path => ':rails_root/documents/:class/:id_partition/:basename.:extension' validates_attachment_presence :file class << self def new(*args) if !(self.name == "Document") return super end doc = super if(doc.file_content_type.nil?) return doc end if !(doc.file_content_type =~ /^image.*/).nil? return Picture.new *args end if !(doc.file_content_type =~ /^audio.*/).nil? return Audio.new *args end if !(doc.file_content_type =~ /^video.*/).nil? return Video.new *args end return doc end end def mime_type Mime::Type.lookup(file_content_type) end def format mime_type.to_sym end # Thumbnail file def thumb helper if format && IMAGE_FORMATS.include?(format.to_s) "formats/#{ format }.png" else "formats/default.png" end end # Thumbnail file def big_thumb helper if format && IMAGE_FORMATS.include?(format.to_s) "formats_big/#{ format }.png" else "formats_big/default.png" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
social_stream-documents-0.1.6 | app/models/document.rb |