From 4434bac3b484006d579b9229a5f69b182644eae7 Mon Sep 17 00:00:00 2001 From: Steve Coast Date: Sat, 7 Apr 2007 14:06:26 +0000 Subject: [PATCH] gpx import now fully works --- app/controllers/trace_controller.rb | 17 ++++++++--------- app/models/trace.rb | 4 ++-- app/views/trace/_trace.rhtml | 2 +- app/views/trace/mine.rhtml | 1 + db/migrate.sql | 1 + 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index 25409cc13..c3ddb5f2d 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -99,23 +99,22 @@ class TraceController < ApplicationController 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 diff --git a/app/models/trace.rb b/app/models/trace.rb index aefe78b60..aa68d9b94 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -1,8 +1,8 @@ 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 diff --git a/app/views/trace/_trace.rhtml b/app/views/trace/_trace.rhtml index 7ba19395b..f6c00448b 100644 --- a/app/views/trace/_trace.rhtml +++ b/app/views/trace/_trace.rhtml @@ -10,7 +10,7 @@ <%= link_to trace.name, {:controller => 'trace', :action => 'view', :display_name => trace.user.display_name, :id => trace.id} %> ... <% if trace.inserted %> - (<%= trace.size %> points) + (<%= trace.size.to_s.gsub(/(\d)(?=(\d{3})+$)/,'\1,') %> points) <% end %> ... <%= time_ago_in_words( trace.timestamp ) %> ago <%= link_to 'more', {:controller => 'trace', :action => 'view', :display_name => trace.user.display_name, :id => trace.id} %> / diff --git a/app/views/trace/mine.rhtml b/app/views/trace/mine.rhtml index 8364bed9e..e403d591b 100644 --- a/app/views/trace/mine.rhtml +++ b/app/views/trace/mine.rhtml @@ -13,6 +13,7 @@
<% if @user %> + <%= start_form_tag({:action => 'create'}, :multipart => true) %>
diff --git a/db/migrate.sql b/db/migrate.sql index 65f0326da..6073c96a7 100644 --- a/db/migrate.sql +++ b/db/migrate.sql @@ -32,3 +32,4 @@ create index users_display_name_idx on users(display_name); alter table users add data_public boolean default false; +alter table gpx_files drop column tmpname; -- 2.43.2