anchor_tags



The previous_tag and next_tag return the enabled/disabled previous/next page anchor tag.

Useful to build minimalistic helpers UIs that don't use nav bar links (e.g. :countless, :keyset paginators).

<%== @pagy.next_tag %>
<%== @pagy.previous_tag %>
Console
require 'pagy/console'
=> true

>> puts @pagy.previous_tag
<a href="/path?example=123&page=2" aria-label="Previous">&lt;</a>
=> nil

>> puts @pagy.next_tag
<a href="/path?example=123&page=4" aria-label="Next">&gt;</a>
=> nil

>> puts @pagy.next_tag(text: 'Show Next', aria_label: 'my-next')
<a href="/path?example=123&page=4" aria-label="my-next">Show Next</a>
=> nil
text: 'My Page'
Override the default text (instead of looking up the pagy.previous/pagy.next entry in the dictionary)
aria_label: 'My Link'
Override the default aria label (instead of looking up the pagy.aria_label.previous/pagy.aria_label.next entry in the dictionary)
absolute: true
Makes the URL absolute.
path: '/my_path'
Overrides the request path in pagination URLs. Use the path only (not the absolute URL). (see Override the request path)
fragment: '...'
URL fragment string.
querify: tweak

Set it to a Lambda to directly edit the passed string-keyed params hash itself. Its result is ignored.

tweak = ->(q) { q.except!('not_useful').merge!('custom' => 'useful') }