orbit-basic/app/models/asset.rb

41 lines
736 B
Ruby
Raw Permalink Normal View History

2010-02-01 09:24:28 +00:00
class Asset
include Mongoid::Document
2011-03-08 09:25:46 +00:00
include Mongoid::Timestamps
2013-04-29 06:59:08 +00:00
include OrbitTag::Taggable
2010-02-01 09:24:28 +00:00
2012-05-17 01:30:21 +00:00
mount_uploader :data, FileAssetUploader
before_save :update_asset_attributes
2010-02-01 09:24:28 +00:00
field :filename
field :description, localize: true
field :title, localize: true
field :content_type
field :file_size
2010-02-01 09:24:28 +00:00
validates :title, :at_least_one => true
validates_presence_of :data
2012-05-16 03:07:11 +00:00
belongs_to :asset_category
belongs_to :assetable, polymorphic: true
2012-05-16 22:28:29 +00:00
before_save :clean_tags
protected
def update_asset_attributes
if data.present? && data_changed?
self.content_type = data.file.content_type
self.file_size = data.file.size
end
end
def clean_tags
2013-05-03 04:11:48 +00:00
self.tagged_ids.delete('')
end
2010-02-05 08:15:16 +00:00
end