gpx import now fully works
This commit is contained in:
parent
f1189ae115
commit
4434bac3b4
5 changed files with 13 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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} %> /
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<br />
|
||||
|
||||
<% if @user %>
|
||||
|
||||
<%= start_form_tag({:action => 'create'}, :multipart => true) %>
|
||||
<table>
|
||||
<table>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue