Class: Attachment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Attachment
- Defined in:
- app/models/attachment.rb
Class Method Summary collapse
Instance Method Summary collapse
- #file_size_human ⇒ Object
- #filename ⇒ Object
- #has_type?(type) ⇒ Boolean
- #medium_url ⇒ Object
- #thumb_url ⇒ Object
Methods inherited from ActiveRecord::Base
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 || re = for type in types if not .content_type re = [] else if .content_type.include? type re = [] end end end re end.flatten end |
Instance Method Details
#file_size_human ⇒ Object
32 33 34 |
# File 'app/models/attachment.rb', line 32 def file_size_human helpers.number_to_human_size( self.file_size ) end |
#filename ⇒ Object
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
24 25 26 |
# File 'app/models/attachment.rb', line 24 def has_type?( type ) self.content_type.include? type end |
#medium_url ⇒ Object
20 21 22 |
# File 'app/models/attachment.rb', line 20 def medium_url file.url(:medium) if has_type? 'image' end |
#thumb_url ⇒ Object
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 |