Module: Pagy::UrlHelpers
- Includes:
- JsonApiExtra::UrlHelperOverride, StandaloneExtra
- Included in:
- Frontend, HeadersExtra, JsonApiExtra::BackendOverride, MetadataExtra
- Defined in:
- lib/pagy/url_helpers.rb
Overview
Provide the helpers to handle the url in frontend and backend
Instance Method Summary collapse
-
#pagy_set_query_params(page, vars, query_params) ⇒ Object
Add the page and items params Overridable by the jsonapi extra.
-
#pagy_url_for(pagy, page, absolute: false, **_) ⇒ Object
Return the URL for the page, relying on the params method and Rack by default.
Instance Method Details
#pagy_set_query_params(page, vars, query_params) ⇒ Object
Add the page and items params Overridable by the jsonapi extra
21 22 23 24 |
# File 'lib/pagy/url_helpers.rb', line 21 def pagy_set_query_params(page, vars, query_params) query_params[vars[:page_param].to_s] = page query_params[vars[:items_param].to_s] = vars[:items] if vars[:items_extra] end |
#pagy_url_for(pagy, page, absolute: false, **_) ⇒ Object
Return the URL for the page, relying on the params method and Rack by default. It supports all Rack-based frameworks (Sinatra, Padrino, Rails, …). For non-rack environments you can use the standalone extra
9 10 11 12 13 14 15 16 17 |
# File 'lib/pagy/url_helpers.rb', line 9 def pagy_url_for(pagy, page, absolute: false, **_) vars = pagy.vars query_params = request.GET query_params.merge!(vars[:params].transform_keys(&:to_s)) if vars[:params].is_a?(Hash) pagy_set_query_params(page, vars, query_params) query_params = vars[:params].(query_params) if vars[:params].is_a?(Proc) query_string = "?#{Rack::Utils.build_nested_query(query_params)}" "#{request.base_url if absolute}#{vars[:request_path] || request.path}#{query_string}#{vars[:fragment]}" end |