From f81f43e501c8f50ccb74bcabc6556f073b91e92a Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 1 Jul 2023 21:53:48 -0700 Subject: [PATCH] Fix deleting grid summons (#112) A bad decision to try to reduce code in `set` made this fail with a 422 because `summon_params` was being tested against but... didn't exist? was nil? I fixed it by not using `set` before calling `destroy`, and just finding the summon in the `destroy` method itself --- app/controllers/api/v1/grid_summons_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/grid_summons_controller.rb b/app/controllers/api/v1/grid_summons_controller.rb index f55101c..156fcd6 100644 --- a/app/controllers/api/v1/grid_summons_controller.rb +++ b/app/controllers/api/v1/grid_summons_controller.rb @@ -5,7 +5,7 @@ module Api class GridSummonsController < Api::V1::ApiController attr_reader :party, :incoming_summon - before_action :set, only: %w[update update_uncap_level update_quick_summon destroy] + before_action :set, only: %w[update update_uncap_level update_quick_summon] before_action :find_party, only: :create before_action :find_incoming_summon, only: :create before_action :authorize, only: %i[create update update_uncap_level update_quick_summon destroy] @@ -111,8 +111,9 @@ module Api end def destroy - render_unauthorized_response if @summon.party.user != current_user - return render json: GridSummonBlueprint.render(@summon, view: :destroyed) if @summon.destroy + summon = GridSummon.find_by('id = ?', params[:id]) + render_unauthorized_response if summon.party.user != current_user + return render json: GridSummonBlueprint.render(summon, view: :destroyed) if summon.destroy end private @@ -142,8 +143,7 @@ module Api end def set - id = summon_params[:id] ? summon_params[:id] : params[:id] - @summon = GridSummon.where('id = ?', id).first + @summon = GridSummon.find_by('id = ?', summon_params[:id]) end # Specify whitelisted properties that can be modified.