FIX: Update position on model when re-positioning record (#24997)

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. 😎
This commit is contained in:
Ted Johansson 2023-12-21 10:15:10 +08:00 committed by GitHub
parent 7fcef5f2f9
commit 25ccf6fab1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -196,8 +196,8 @@ class CategoriesController < ApplicationController
category_params.delete(:custom_fields) category_params.delete(:custom_fields)
# properly null the value so the database constraint doesn't catch us # 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[:email_in] = nil if category_params[:email_in].blank?
category_params[:minimum_required_tags] = 0 if category_params[:minimum_required_tags]&.blank? category_params[:minimum_required_tags] = 0 if category_params[:minimum_required_tags].blank?
old_permissions = cat.permissions_params old_permissions = cat.permissions_params
old_permissions = { "everyone" => 1 } if old_permissions.empty? old_permissions = { "everyone" => 1 } if old_permissions.empty?

View File

@ -33,5 +33,7 @@ module Positionable
WHERE id = :id", WHERE id = :id",
id: id, id: id,
position: position position: position
self.position = position
end end
end end