Class: Attachment

Inherits:
ActiveRecord::Base show all
Defined in:
app/models/attachment.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveRecord::Base

#readonly?

Class Method Details

.find_by_type(type) ⇒ Object



36
37
38
# File 'app/models/attachment.rb', line 36

def self.find_by_type( type )
  where( "content_type like ?", "%" + type + "%" )
end

.find_without_types(*types) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/attachment.rb', line 40

def self.find_without_types( *types )
  self.where(true).to_a.collect do |attachment|
    re = attachment
    for type in types
      if not attachment.content_type
        re = []
      else
        if attachment.content_type.include? type
          re = []
        end
      end
    end
    re
  end.flatten
end

Instance Method Details

#file_size_humanObject



32
33
34
# File 'app/models/attachment.rb', line 32

def file_size_human
  helpers.number_to_human_size( self.file_size )
end

#filenameObject



28
29
30
# File 'app/models/attachment.rb', line 28

def filename 
  self.file.to_s.split( "/" ).last if self.file
end

#has_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/models/attachment.rb', line 24

def has_type?( type )
  self.content_type.include? type
end

#medium_urlObject



20
21
22
# File 'app/models/attachment.rb', line 20

def medium_url
  file.url(:medium) if has_type? 'image'
end

#thumb_urlObject



13
14
15
16
17
18
# File 'app/models/attachment.rb', line 13

def thumb_url
  url = file.url( :thumb ) if has_type?( "image" ) or has_type?( "pdf" )
  url = file.url( :video_thumb ) if has_type?( "video" )
  url = helpers.image_path( 'file.png' ) unless url
  return url
end