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:
parent
7be6a372bf
commit
a4d10097d5
5 changed files with 41 additions and 15 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue