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
10 has_many :points, :class_name => 'Tracepoint', :foreign_key => 'gpx_id', :dependent => :destroy
13 self.tags = s.split().collect {|tag|
20 def large_picture= (data)
21 f = File.new(large_picture_name, "wb")
26 def icon_picture= (data)
27 f = File.new(icon_picture_name, "wb")
33 f = File.new(large_picture_name, "rb")
34 logger.info "large picture file: '#{f.path}', bytes: #{File.size(f.path)}"
35 data = f.sysread(File.size(f.path))
36 logger.info "have read data, bytes: '#{data.length}'"
42 f = File.new(icon_picture_name, "rb")
43 logger.info "icon picture file: '#{f.path}'"
44 data = f.sysread(File.size(f.path))
49 # FIXME change to permanent filestore area
50 def large_picture_name
51 "/home/osm/icons/#{id}.gif"
54 # FIXME change to permanent filestore area
56 "/home/osm/icons/#{id}_icon.gif"
60 el1 = XML::Node.new 'gpx_file'
61 el1['id'] = self.id.to_s
62 el1['name'] = self.name.to_s
63 el1['lat'] = self.latitude.to_s
64 el1['lon'] = self.longitude.to_s
65 el1['user'] = self.user.display_name
66 el1['public'] = self.public.to_s
67 el1['pending'] = (!self.inserted).to_s
68 el1['timestamp'] = self.timestamp.xmlschema