Orbit/app/models/asset.rb

41 lines
736 B
Ruby

class Asset
include Mongoid::Document
include Mongoid::Timestamps
include OrbitTag::Taggable
mount_uploader :data, FileAssetUploader
before_save :update_asset_attributes
field :filename
field :description, localize: true
field :title, localize: true
field :content_type
field :file_size
validates :title, :at_least_one => true
validates_presence_of :data
belongs_to :asset_category
belongs_to :assetable, polymorphic: true
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
self.tagged_ids.delete('')
end
end