From af518699275d92c810e2ac5776144f371f099cb1 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 21 Dec 2022 16:20:00 -0800 Subject: [PATCH] Fix build_conditions method The method of assigning values was assigning nil if the value wasn't present in `params`, which is bad --- app/controllers/api/v1/parties_controller.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/v1/parties_controller.rb b/app/controllers/api/v1/parties_controller.rb index ccf131d..b8b949d 100644 --- a/app/controllers/api/v1/parties_controller.rb +++ b/app/controllers/api/v1/parties_controller.rb @@ -55,6 +55,7 @@ module Api def index conditions = build_conditions(request.params) + ap conditions @parties = Party.where(conditions) .order(created_at: :desc) @@ -105,12 +106,12 @@ module Api .to_datetime.beginning_of_day end - { - element: (params['element'] unless params['element'].blank?), - raid: (params['raid'] unless params['raid'].blank?), - created_at: (start_time..now unless params['recency'].blank?), - weapons_count: 5..13 - } + {}.tap do |hash| + hash[:element] = params['element'] unless params['element'].blank? + hash[:raid] = params['raid'] unless params['raid'].blank? + hash[:created_at] = start_time..now unless params['recency'].blank? + hash[:weapons_count] = 5..13 + end end def random_string