1 class TraceController < ApplicationController
2 before_filter :authorize_web
6 @traces = Trace.find(:all)
10 @traces = Trace.find(:all, :conditions => ['user_id = ?', @user.id])
14 @trace = Trace.find(params[:id])
15 render :nothing, :status => 401 if @trace.user.id != @user.id
19 filename = "/tmp/#{rand}"
21 File.open(filename, "w") { |f| f.write(@params['trace']['gpx_file'].read) }
22 @params['trace']['name'] = @params['trace']['gpx_file'].original_filename.gsub(/[^a-zA-Z0-9.]/, '_') # This makes sure filenames are sane
23 @params['trace'].delete('gpx_file') # let's remove the field from the hash, because there's no such field in the DB anyway.
24 @trace = Trace.new(@params['trace'])
25 @trace.inserted = false
26 @trace.user_id = @user.id
27 @trace.timestamp = Time.now
29 logger.info("id is #{@trace.id}")
30 `mv #{filename} /tmp/#{@trace.id}.gpx`
31 flash[:notice] = "Your GPX file has been uploaded and is awaiting insertion in to the database. This will usually happen within half an hour, and an email will be sent to you on completion."
34 redirect_to :action => 'mine'
38 trace = Trace.find(params[:id])
39 send_data(trace.large_picture, :filename => "#{trace.id}.gif", :type => 'image/png', :disposition => 'inline') if trace.public
43 trace = Trace.find(params[:id])
44 send_data(trace.icon_picture, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline') if trace.public