Refactor the from_xml methods to act on existing trace objects.

Setting the new tags with the = operator takes care of removing the
old ones, and is the same approach as taken by the tagstring= method.

Fixes #1600
This commit is contained in:
Andy Allan 2017-08-18 10:08:54 +01:00
parent e9324ad681
commit c647aa3d4d
3 changed files with 16 additions and 25 deletions

View file

@ -263,15 +263,7 @@ class TraceController < ApplicationController
trace = Trace.visible.find(params[:id])
if trace.user == current_user
new_trace = Trace.from_xml(request.raw_post)
unless new_trace && new_trace.id == trace.id
raise OSM::APIBadUserInput.new("The id in the url (#{trace.id}) is not the same as provided in the xml (#{new_trace.id})")
end
trace.description = new_trace.description
trace.tags = new_trace.tags
trace.visibility = new_trace.visibility
trace.from_xml(request.raw_post)
trace.save!
head :ok