File.open(filename, "w") { |f| f.write(@params['trace']['gpx_file'].read) }
@params['trace']['name'] = @params['trace']['gpx_file'].original_filename.gsub(/[^a-zA-Z0-9.]/, '_') # This makes sure filenames are sane
- @params['trace'].delete('gpx_file') # let's remove the field from the hash, because there's no such field in the DB anyway.
+ @params['trace'].delete('gpx_file') # remove the field from the hash, because there's no such field in the DB
@trace = Trace.new(@params['trace'])
@trace.inserted = false
- @trace.user_id = @user.id
+ @trace.user = @user
@trace.timestamp = Time.now
- saved_filename = "/tmp/#{@trace.id}.gpx"
- # *nix - specific `mv #{filename} /tmp/#{@trace.id}.gpx`
- File.rename(filename, saved_filename)
- @trace.tmpname = saved_filename
+
if @trace.save
+ saved_filename = "/tmp/#{@trace.id}.gpx"
+ File.rename(filename, saved_filename)
+
logger.info("id is #{@trace.id}")
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."
+ redirect_to :action => 'mine'
else
- #TODO upload failure
+# render :action => 'mine'
end
-
- redirect_to :action => 'mine'
end
def georss
class Trace < ActiveRecord::Base
set_table_name 'gpx_files'
- validates_presence_of :user_id, :name, :public, :description, :tmpname, :timestamp
- validates_numericality_of :latitude, :longitude
+ validates_presence_of :user_id, :name, :public, :description, :timestamp
+# validates_numericality_of :latitude, :longitude
validates_inclusion_of :inserted, :in => [ true, false]
belongs_to :user
<td class="<%= cl %>"><%= link_to trace.name, {:controller => 'trace', :action => 'view', :display_name => trace.user.display_name, :id => trace.id} %>
<span class="gpxsummary" title="<%= trace.timestamp %>"> ...
<% if trace.inserted %>
- (<%= trace.size %> points)
+ (<%= trace.size.to_s.gsub(/(\d)(?=(\d{3})+$)/,'\1,') %> points)
<% end %>
... <%= time_ago_in_words( trace.timestamp ) %> ago</span>
<%= link_to 'more', {:controller => 'trace', :action => 'view', :display_name => trace.user.display_name, :id => trace.id} %> /
<br />
<% if @user %>
+
<%= start_form_tag({:action => 'create'}, :multipart => true) %>
<table>
<table>
alter table users add data_public boolean default false;
+alter table gpx_files drop column tmpname;