Module: Pagy::StandaloneExtra

Included in:
UrlHelpers
Defined in:
lib/pagy/extras/standalone.rb

Overview

Use pagy without any request object, nor Rack environment/gem, nor any defined params method, even in the irb/rails console without any app or config.

Defined Under Namespace

Modules: QueryUtils

Instance Method Summary collapse

Instance Method Details

#pagy_url_for(pagy, page, absolute: false, **_) ⇒ Object

Return the URL for the page. If there is no pagy.vars it works exactly as the regular #pagy_url_for, relying on the params method and Rack. If there is a defined pagy.vars variable it does not need the params method nor Rack.



41
42
43
44
45
46
47
48
49
50
# File 'lib/pagy/extras/standalone.rb', line 41

def pagy_url_for(pagy, page, absolute: false, **_)
  return super unless pagy.vars[:url]

  vars         = pagy.vars
  params       = pagy.params.is_a?(Hash) ? pagy.params.clone : {}  # safe when it gets reused
  pagy_set_query_params(page, vars, params)
  params       = pagy.params.call(params) if pagy.params.is_a?(Proc)
  query_string = "?#{QueryUtils.build_nested_query(params)}"
  "#{vars[:url]}#{query_string}#{vars[:fragment]}"
end