This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/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