From: Thomas Wood Date: Fri, 23 Jan 2009 19:14:21 +0000 (+0000) Subject: Set params to sane defaults if unset by client. X-Git-Tag: live~7557^2~73 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/1522ed275c3efceb9629438e0272f2f2d4adf5ba Set params to sane defaults if unset by client. Reject creates with no file with 400, model validations will also reject with 400 (as was existing but broken behaviour) Closes #1510 --- diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index 47041b491..6528dffde 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -279,12 +279,20 @@ class TraceController < ApplicationController def api_create if request.post? - do_create(params[:file], params[:tags], params[:description], params[:public]) + tags = params[:tags] || "" + description = params[:description] || "" + pub = params[:public] || false + + if params[:file].respond_to?(:read) + do_create(params[:file], tags, description, pub) - if @trace.id - render :text => @trace.id.to_s, :content_type => "text/plain" - elsif @trace.valid? - render :nothing => true, :status => :internal_server_error + if @trace.id + render :text => @trace.id.to_s, :content_type => "text/plain" + elsif @trace.valid? + render :nothing => true, :status => :internal_server_error + else + render :nothing => true, :status => :bad_request + end else render :nothing => true, :status => :bad_request end