Repository navigation
Question: page_key symbol vs string after upgrade #849
|
Hi! I upgraded Pagy recently and noticed a small behavior change I wanted to confirm is expected. Looking at the request code, it seems params are converted into a plain Ruby pagy/gem/lib/pagy/classes/request.rb Line 14 in 439edee My guess is this was done intentionally for compatibility with non-Rails apps (i.e., to avoid depending on ActiveSupport), which totally makes sense. In my Rails app, though, this affected When I pass it as a symbol, pagination doesn’t pick up the param: @pagy, @records = pagy(scope, limit: 10, page_key: :team_page)But it works if I pass the key as a string: @pagy, @records = pagy(scope, limit: 10, page_key: "team_page")Is this difference (string-only keys for params, and therefore Happy to put together a minimal reproduction if that helps. Thanks! |
Replies: 1 comment
|
Hi @thiagopradi, you got it right. URLs are strings, Indifferent access hashes are string-keyed when converted to regular hashes, Rack::Request params are string keyed to avoid converting symbols back and forth between methods/statements during URL composition. The old pagy was a mixed bag doing a lot of useless conversions, so they are end2end string keyed now. The change has been reported as a breaking change in the upgrade guide, but admittedly we should move all that scattered info (and options) about URLs into a single resource page in the docs.
HTH |
Hi @thiagopradi, you got it right.
URLs are strings, Indifferent access hashes are string-keyed when converted to regular hashes, Rack::Request params are string keyed to avoid converting symbols back and forth between methods/statements during URL composition.
The old pagy was a mixed bag doing a lot of useless conversions, so they are end2end string keyed now. The change has been reported as a breaking change in the upgrade guide, but admittedly we should move all that scattered info (and options) about URLs into a single resource page in the docs.
Will do ASAP.Added: URLs docs
HTH