]> git.openstreetmap.org Git - rails.git/blob - app/models/trace.rb
f74b1d0091c3d4c06093135a18d14acec903df33
[rails.git] / app / models / trace.rb
1 class Trace < ActiveRecord::Base
2   set_table_name 'gpx_files'
3
4   belongs_to :user
5   has_many :tags, :class_name => 'Tracetag', :foreign_key => 'gpx_id', :dependent => :destroy
6
7   def tagstring=(s)
8     self.tags = s.split().collect {|tag|
9       tt = Tracetag.new
10       tt.tag = tag
11       tt
12     }
13   end\r
14   \r
15   def large_picture= (data)\r
16     f = File.new(large_picture_name, "wb")\r
17     f.syswrite(data)\r
18     f.close\r
19   end\r
20   \r
21   def icon_picture= (data)\r
22     f = File.new(icon_picture_name, "wb")\r
23     f.syswrite(data)\r
24     f.close\r
25   end\r
26 \r
27   def large_picture\r
28     f = File.new(large_picture_name, "rb")\r
29     logger.info "large picture file: '#{f.path}', bytes: #{File.size(f.path)}"\r
30     data = f.sysread(File.size(f.path))\r
31     logger.info "have read data, bytes: '#{data.length}'"\r
32     f.close\r
33     data\r
34   end\r
35   \r
36   def icon_picture\r
37     f = File.new(icon_picture_name, "rb")\r
38     logger.info "icon picture file: '#{f.path}'"\r
39     data = f.sysread(File.size(f.path))\r
40     f.close\r
41     data\r
42   end\r
43   \r
44   # FIXME change to permanent filestore area\r
45   def large_picture_name\r
46     "/tmp/#{id}.gif"\r
47   end\r
48 \r
49   # FIXME change to permanent filestore area\r
50   def icon_picture_name\r
51     "/tmp/#{id}_icon.gif"\r
52   end\r
53 end