]> git.openstreetmap.org Git - rails.git/commitdiff
gpx import now fully works
authorSteve Coast <steve@asklater.com>
Sat, 7 Apr 2007 14:06:26 +0000 (14:06 +0000)
committerSteve Coast <steve@asklater.com>
Sat, 7 Apr 2007 14:06:26 +0000 (14:06 +0000)
app/controllers/trace_controller.rb
app/models/trace.rb
app/views/trace/_trace.rhtml
app/views/trace/mine.rhtml
db/migrate.sql

index 25409cc130c5ae9c519690cf5207335e99cec5d9..c3ddb5f2d8c1382edd1ad862ac3325ee999a2384 100644 (file)
@@ -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
index aefe78b6000e5a2ab3e198cef3887e9ad0342945..aa68d9b9408616784ccf8f60b70573f8f9cdc6cb 100644 (file)
@@ -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
index 7ba19395b2e886cff186d0aefdbd0505e4e8ad50..f6c00448be28fd93fc4060f35759ad3cecf96d7a 100644 (file)
@@ -10,7 +10,7 @@
   <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} %> /
index 8364bed9e8816b88bad077efcef8ee582c395c44..e403d591bba707566b53cc1155c44919ad38c18b 100644 (file)
@@ -13,6 +13,7 @@
 <br />
 
 <% if @user %>
+
 <%= start_form_tag({:action => 'create'}, :multipart => true) %>
 <table>
 <table>
index 65f0326da6aee72b423ab436f81468a65d8e3127..6073c96a7dae960dd67cb9a41fb2b498deefddf9 100644 (file)
@@ -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;