From c24b0e93997bcd6bcad475d9ba0adfe86fa01ea6 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 26 Jun 2019 12:52:21 +0200 Subject: [PATCH] Rework to ensure views are named after the controller method name --- app/controllers/api/traces_controller.rb | 9 ++------- app/controllers/api/users_controller.rb | 2 +- app/views/api/traces/show.builder | 5 +++++ .../{traces/trace.builder => users/gpx_files.builder} | 4 +--- 4 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 app/views/api/traces/show.builder rename app/views/api/{traces/trace.builder => users/gpx_files.builder} (53%) diff --git a/app/controllers/api/traces_controller.rb b/app/controllers/api/traces_controller.rb index fd43a1d44..8979704a7 100644 --- a/app/controllers/api/traces_controller.rb +++ b/app/controllers/api/traces_controller.rb @@ -16,14 +16,9 @@ module Api around_action :api_call_handle_error def show - trace = Trace.visible.find(params[:id]) + @trace = Trace.visible.find(params[:id]) - if trace.public? || trace.user == current_user - @traces = [trace] - render "trace" - else - head :forbidden - end + head :forbidden unless @trace.public? || @trace.user == current_user end def update diff --git a/app/controllers/api/users_controller.rb b/app/controllers/api/users_controller.rb index e6922e0a0..43d5ec908 100644 --- a/app/controllers/api/users_controller.rb +++ b/app/controllers/api/users_controller.rb @@ -38,7 +38,7 @@ module Api def gpx_files @traces = current_user.traces.reload - render "api/traces/trace", :content_type => "application/xml" + render :content_type => "application/xml" end private diff --git a/app/views/api/traces/show.builder b/app/views/api/traces/show.builder new file mode 100644 index 000000000..f4a4e4d2e --- /dev/null +++ b/app/views/api/traces/show.builder @@ -0,0 +1,5 @@ +xml.instruct! :xml, :version => "1.0" + +xml.osm(OSM::API.new.xml_root_attributes) do |osm| + osm << render(@trace) +end diff --git a/app/views/api/traces/trace.builder b/app/views/api/users/gpx_files.builder similarity index 53% rename from app/views/api/traces/trace.builder rename to app/views/api/users/gpx_files.builder index 1e278f770..d5287ffbd 100644 --- a/app/views/api/traces/trace.builder +++ b/app/views/api/users/gpx_files.builder @@ -1,9 +1,7 @@ xml.instruct! :xml, :version => "1.0" -# basic attributes - xml.osm(OSM::API.new.xml_root_attributes) do |osm| @traces.each do |trace| - osm << render(:partial => "api/traces/trace.builder", :locals => { :trace => trace }) + osm << render(:partial => "api/traces/trace", :locals => { :trace => trace }) end end -- 2.39.5