1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 07:39:39 +02:00

Preserve pagination on entry updates (#1563)

* Preserve pagination on entry updates

* Test fix
This commit is contained in:
Zach Gollwitzer 2024-12-20 11:24:46 -05:00 committed by GitHub
parent 7be6a372bf
commit a4d10097d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 41 additions and 15 deletions

View file

@ -166,4 +166,24 @@ module ApplicationHelper
cookies[:admin] == "true"
end
def custom_pagy_url_for(pagy, page, current_path: nil)
if current_path.blank?
pagy_url_for(pagy, page)
else
uri = URI.parse(current_path)
params = URI.decode_www_form(uri.query || "").to_h
# Delete existing page param if it exists
params.delete("page")
# Add new page param unless it's page 1
params["page"] = page unless page == 1
if params.empty?
uri.path
else
"#{uri.path}?#{URI.encode_www_form(params)}"
end
end
end
end