1 class Trace < ActiveRecord::Base
2 set_table_name 'gpx_files'
4 validates_presence_of :user_id, :name, :public, :description, :timestamp
5 # validates_numericality_of :latitude, :longitude
6 validates_inclusion_of :inserted, :in => [ true, false]
9 has_many :tags, :class_name => 'Tracetag', :foreign_key => 'gpx_id', :dependent => :destroy
12 self.tags = s.split().collect {|tag|
19 def large_picture= (data)
20 f = File.new(large_picture_name, "wb")
25 def icon_picture= (data)
26 f = File.new(icon_picture_name, "wb")
32 f = File.new(large_picture_name, "rb")
33 logger.info "large picture file: '#{f.path}', bytes: #{File.size(f.path)}"
34 data = f.sysread(File.size(f.path))
35 logger.info "have read data, bytes: '#{data.length}'"
41 f = File.new(icon_picture_name, "rb")
42 logger.info "icon picture file: '#{f.path}'"
43 data = f.sysread(File.size(f.path))
48 # FIXME change to permanent filestore area
49 def large_picture_name
53 # FIXME change to permanent filestore area
59 el1 = XML::Node.new 'gpx_file'
60 el1['id'] = self.id.to_s
61 el1['name'] = self.name.to_s
62 el1['lat'] = self.latitude.to_s
63 el1['lon'] = self.longitude.to_s
64 el1['user'] = self.user.display_name
65 el1['public'] = self.public.to_s
66 el1['pending'] = (!self.inserted).to_s
67 el1['timestamp'] = self.timestamp.xmlschema