Orbit/app/models/asset.rb

32 lines
604 B
Ruby

class Asset
include MongoMapper::Document
include Grip::HasAttachment
key :filename, String, :required => true
key :description, String
has_grid_attachment :data, :required => true
before_validation :setup_filename
after_save :save_static_file
def url
"/assets/#{self.filename}"
end
protected
def setup_filename
if self.filename.blank? && self.data
self.filename = self.data.file_name
end
end
def save_static_file
f = File.new("#{RAILS_ROOT}/public/assets/#{self.filename}", "wb")
f.write(self.data.file.read)
f.close
end
end