From: Gabriel Ebner Date: Wed, 26 Sep 2007 14:15:21 +0000 (+0000) Subject: rails_port_0.5: Merge rails_port. X-Git-Tag: live~8996^2~9 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/16a641ac2a663ea926566a5cca2575ee295e8555?hp=4bbe59a0c4c0a54de0fe41b1ee3e0d1d686eba66 rails_port_0.5: Merge rails_port. --- diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index 3eb7f5c7e..7c5bd7db0 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -94,17 +94,26 @@ class TraceController < ApplicationController end def create - name = params[:trace][:gpx_file].original_filename.gsub(/[^a-zA-Z0-9.]/, '_') # This makes sure filenames are sane + logger.info(params[:trace][:gpx_file].class.name) + if params[:trace][:gpx_file].respond_to?(:read) + do_create(params[:trace][:gpx_file], params[:trace][:tagstring], + params[:trace][:description], params[:trace][:public]) - do_create(name, params[:trace][:tagstring], params[:trace][:description], params[:trace][:public]) do |f| - f.write(params[:trace][:gpx_file].read) - end - - if @trace.id - 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." + if @trace.id + 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' + redirect_to :action => 'mine' + end + else + @trace = Trace.new({:name => "Dummy", + :tagstring => params[:trace][:tagstring], + :description => params[:trace][:description], + :public => params[:trace][:public], + :inserted => false, :user => @user, + :timestamp => Time.now}) + @trace.valid? + @trace.errors.add(:gpx_file, "can't be blank") end end @@ -259,11 +268,7 @@ class TraceController < ApplicationController def api_create if request.post? - name = params[:file].original_filename.gsub(/[^a-zA-Z0-9.]/, '_') # This makes sure filenames are sane - - do_create(name, params[:tags], params[:description], params[:public]) do |f| - f.write(params[:file].read) - end + do_create(params[:file], params[:tags], params[:description], params[:public]) if @trace.id render :text => @trace.id.to_s, :content_type => "text/plain" @@ -279,10 +284,11 @@ class TraceController < ApplicationController private - def do_create(name, tags, description, public) + def do_create(file, tags, description, public) + name = file.original_filename.gsub(/[^a-zA-Z0-9.]/, '_') filename = "/tmp/#{rand}" - File.open(filename, "w") { |f| yield f } + File.open(filename, "w") { |f| f.write(file.read) } @trace = Trace.new({:name => name, :tagstring => tags, :description => description, :public => public}) diff --git a/app/views/trace/_trace_form.rhtml b/app/views/trace/_trace_form.rhtml new file mode 100644 index 000000000..299845015 --- /dev/null +++ b/app/views/trace/_trace_form.rhtml @@ -0,0 +1,9 @@ +<% form_for :trace, @trace, :url => { :action => "create" }, :html => { :multipart => true } do |f| %> + + + + + + +
Upload GPX File<%= f.file_field :gpx_file, :size => 50, :maxlength => 255 %>
Description<%= f.text_field :description, :size => 50, :maxlength => 255 %>
Tags<%= f.text_field :tagstring, :size => 50, :maxlength => 255 %>
Public?<%= f.check_box :public %>
<%= submit_tag 'Upload' %> | Help
+<% end %> diff --git a/app/views/trace/create.rhtml b/app/views/trace/create.rhtml index db9dc385c..94f403951 100644 --- a/app/views/trace/create.rhtml +++ b/app/views/trace/create.rhtml @@ -2,14 +2,4 @@ <%= 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 %> +<%= render :partial => 'trace_form' %> diff --git a/app/views/trace/mine.rhtml b/app/views/trace/mine.rhtml index 291217753..7deaa1831 100644 --- a/app/views/trace/mine.rhtml +++ b/app/views/trace/mine.rhtml @@ -1,16 +1,3 @@ <%= render :partial => 'trace_header' %> - -<% 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', {:checked => 'checked'}) %>
-<%= submit_tag 'Upload' %> | help -
-<% end %> - +<%= render :partial => 'trace_form' %> <%= render :partial => 'trace_list' %>