Skip to content

Instantly share code, notes, and snippets.

@klausmeyer
Created October 26, 2021 15:22
Show Gist options
  • Save klausmeyer/2accc9aebbd3e60a7af74ad8cb5ac20f to your computer and use it in GitHub Desktop.
Save klausmeyer/2accc9aebbd3e60a7af74ad8cb5ac20f to your computer and use it in GitHub Desktop.
Pagy Issue
require "bundler/inline"
gemfile(install: true) do
source "https://rubygems.org"
gem "rails", "~> 6.1.0"
gem "pagy", "5.1.2"
end
gem "actionpack"
gem "railties"
require "rails"
require "action_controller/railtie"
require "active_record"
class TestApp < Rails::Application
config.eager_load = "development"
config.consider_all_requests_local = true
config.secret_key_base = "anything"
config.secret_token = "anything"
config.hosts = "www.example.com"
routes.append do
get "/" => "test#index", as: "test"
end
end
require "pagy/extras/metadata"
require "pagy/extras/overflow"
Pagy::DEFAULT[:items] = 20
Pagy::DEFAULT[:metadata] = [:first_url, :last_url]
Pagy::DEFAULT[:overflow] = :empty_page
class Record < ActiveRecord::Base; end
class TestController < ActionController::Base
include Pagy::Backend
def index
meta, records = pagy(Record.none, items: 10)
render json: {data: [], meta: pagy_metadata(meta)}
end
end
TestApp.initialize!
session = ActionDispatch::Integration::Session.new(Rails.application)
path = Rails.application.routes.url_helpers.test_path
session.get(path)
puts session.response.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment