Skip to content

Commit

Permalink
FIX: Update position on model when re-positioning record (#24997)
Browse files Browse the repository at this point in the history
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. 😎
  • Loading branch information
Drenmi committed Dec 21, 2023
1 parent 7fcef5f commit 25ccf6f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/categories_controller.rb
Expand Up @@ -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?
Expand Down
2 changes: 2 additions & 0 deletions app/models/concerns/positionable.rb
Expand Up @@ -33,5 +33,7 @@ def move_to(position_arg)
WHERE id = :id",
id: id,
position: position

self.position = position
end
end

0 comments on commit 25ccf6f

Please sign in to comment.