Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Dec 21, 2023

Conversation

Drenmi
Copy link
Contributor

@Drenmi Drenmi commented Dec 21, 2023

What is happening?

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.

Why is it happening?

The Positionable concern correctly positions the record and updates the database, but we don't assign the new position to the already instantiated model.

How does this fix it?

EZPZ, just assign self.position after the database update. 馃槑

@@ -33,5 +33,7 @@ def move_to(position_arg)
WHERE id = :id",
id: id,
position: position

self.position = position
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the relevant change right here.

Comment on lines +199 to +200
category_params[:email_in] = nil if category_params[:email_in].blank?
category_params[:minimum_required_tags] = 0 if category_params[:minimum_required_tags].blank?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjacent code cleanup. No need to use lonely operator when calling #blank? since it's defined one nil as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is a weird oversight...also never heard this called the "lonely operator" 馃槅

Comment on lines +199 to +200
category_params[:email_in] = nil if category_params[:email_in].blank?
category_params[:minimum_required_tags] = 0 if category_params[:minimum_required_tags].blank?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is a weird oversight...also never heard this called the "lonely operator" 馃槅

@Drenmi Drenmi merged commit 25ccf6f into main Dec 21, 2023
19 checks passed
@Drenmi Drenmi deleted the fix/update-position-on-model-when-positioning branch December 21, 2023 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants