From bd5793f7a6eb8f2c49f08f7fd66bd35abd4a37c3 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 12 Jun 2007 08:52:19 +0000 Subject: [PATCH] Improve reporting of errors in GPX uploads, and allow private traces to be uploaded once again. --- app/controllers/trace_controller.rb | 6 +----- app/models/trace.rb | 8 ++++++-- app/views/trace/create.rhtml | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 app/views/trace/create.rhtml diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index 262dd8d2f..b4bf36169 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -2,7 +2,7 @@ class TraceController < ApplicationController before_filter :authorize_web before_filter :authorize, :only => [:api_details, :api_data, :api_create] layout 'site' - + # Counts and selects pages of GPX traces for various criteria (by user, tags, public etc.). # target_user - if set, specifies the user to fetch traces for. if not set will fetch all traces # paging_action - the action that will be linked back to from view @@ -115,10 +115,6 @@ class TraceController < ApplicationController 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 - # fixme throw an error here - redirect_to :action => 'mine' - flash[:notice] = "You haven't entered a tag or a description for yoru traces." end end diff --git a/app/models/trace.rb b/app/models/trace.rb index 11f912b69..eccd3af1f 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -1,10 +1,10 @@ class Trace < ActiveRecord::Base set_table_name 'gpx_files' - validates_presence_of :user_id, :name, :public, :timestamp + validates_presence_of :user_id, :name, :timestamp validates_presence_of :description, :on => :create # validates_numericality_of :latitude, :longitude - validates_inclusion_of :inserted, :in => [ true, false] + validates_inclusion_of :public, :inserted, :in => [ true, false] belongs_to :user has_many :tags, :class_name => 'Tracetag', :foreign_key => 'gpx_id', :dependent => :delete_all @@ -15,6 +15,10 @@ class Trace < ActiveRecord::Base FileUtils.rm_f(trace_name, icon_picture_name, large_picture_name) end + def tagstring + return tags.collect {|tt| tt.tag}.join(" ") + end + def tagstring=(s) self.tags = s.split().collect {|tag| tt = Tracetag.new diff --git a/app/views/trace/create.rhtml b/app/views/trace/create.rhtml new file mode 100644 index 000000000..db9dc385c --- /dev/null +++ b/app/views/trace/create.rhtml @@ -0,0 +1,15 @@ +

Upload GPS Trace

+ +<%= error_messages_for 'trace' %> + +<% form_tag({:action => 'create'}, :multipart => true) do %> + + + + + + +
Upload GPX File<%= file_field('trace', 'gpx_file', {:size => 50, :maxlength => 255}) %>
Description<%= text_field('trace', 'description', {:size => 50, :maxlength => 255}) %>
Tags<%= text_field('trace', 'tagstring', {:size => 50, :maxlength => 255}) %>
Public?<%= check_box('trace', 'public') %>
+<%= submit_tag 'Upload' %> | help +
+<% end %> -- 2.43.2