]> git.openstreetmap.org Git - rails.git/blob - app/controllers/trace_controller.rb
0b39d52ce8b8def2d51b00494bfa4bb054309ac5
[rails.git] / app / controllers / trace_controller.rb
1 class TraceController < ApplicationController
2   before_filter :authorize_web  
3   layout 'site'
4
5   def list
6     @traces = Trace.find(:all)
7   end
8
9   def mine
10     @traces = Trace.find(:all, :conditions => ['user_id = ?', @user.id])
11   end
12
13   def create
14     @params['trace']['name'] = @params['trace']['gpx_file'].original_filename.gsub(/[^a-zA-Z0-9.]/, '_') # This makes sure filenames are sane
15     @params['trace']['data'] = @params['trace']['gpx_file'].read
16     @params['trace']['mime_type'] = @params['trace']['gpx_file'].content_type.chomp
17     @params['trace'].delete('gpx_file') # let's remove the field from the hash, because there's no such field in the DB anyway.
18     @trace = Trace.new(@params['trace'])
19     @trace.inserted = false
20     @trace.user_id = @user.id
21     @trace.timestamp = Time.now
22     if @trace.save
23       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."
24     end
25
26     redirect_to :action => 'mine'
27   end
28 end