geared_pagination
geared_pagination copied to clipboard
Add option to configure the cursor/param name
Description
This pull request adds the ability to customize the cursor query parameter name.
Changes
The cursor_name
configuration option can now be set to a custom value in the GearedPagination.configure
block. By default, the cursor parameter is named :page
, but it can now be customized.
The reason for this change is to provide more flexibility for developers who may want to use a different query parameter name for pagination cursors, for example to avoid conflicts with other query parameters in their application or where the FE expects a specific name for the cursor param.
Usage
GearedPagination.configure do |config|
config.cursor_name = :cursor
end
You can also use the cursor parameter name in your links to generate pagination URLs:
<%= link_to "Next page", messages_path(cursor: @page.next_param) %>
This will generate a URL with a ?cursor=<next_cursor>
query parameter instead of ?page=<next_page>
.
Additional Notes
This pull request includes tests to ensure that the cursor_name
option is working as expected, and that links with custom cursor parameter names are generated correctly.