From 25ccf6fab1f9a513a65e162ac14a0f160e81a13b Mon Sep 17 00:00:00 2001 From: Ted Johansson Date: Thu, 21 Dec 2023 10:15:10 +0800 Subject: [PATCH] FIX: Update position on model when re-positioning record (#24997) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When updating the position of a category, the server correctly updates the position in the database, but the response sent back to the client still contains the old position, causing it to "flip back" in the UI when saving. Only reloading the page will reveal the new, correct value. The Positionable concern correctly positions the record and updates the database, but we don't assign the new position to the already instantiated model. This change just assigns self.position after the database update. 😎 --- app/controllers/categories_controller.rb | 4 ++-- app/models/concerns/positionable.rb | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 20c6d6b23f20b..d143ff8e6d962 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -196,8 +196,8 @@ def update category_params.delete(:custom_fields) # properly null the value so the database constraint doesn't catch us - category_params[:email_in] = nil if category_params[:email_in]&.blank? - category_params[:minimum_required_tags] = 0 if category_params[:minimum_required_tags]&.blank? + category_params[:email_in] = nil if category_params[:email_in].blank? + category_params[:minimum_required_tags] = 0 if category_params[:minimum_required_tags].blank? old_permissions = cat.permissions_params old_permissions = { "everyone" => 1 } if old_permissions.empty? diff --git a/app/models/concerns/positionable.rb b/app/models/concerns/positionable.rb index 6ee93cdf4c924..66b854f97be0e 100644 --- a/app/models/concerns/positionable.rb +++ b/app/models/concerns/positionable.rb @@ -33,5 +33,7 @@ def move_to(position_arg) WHERE id = :id", id: id, position: position + + self.position = position end end