{"id":16102374,"url":"https://github.com/sshaw/page_number","last_synced_at":"2025-09-12T17:42:04.210Z","repository":{"id":56887250,"uuid":"85371497","full_name":"sshaw/page_number","owner":"sshaw","description":"Page number validation. Utility methods for pagination page and per page that make sure you'll always have a valid number","archived":false,"fork":false,"pushed_at":"2025-06-21T03:00:47.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-05T09:21:19.217Z","etag":null,"topics":["kaminari","pagination","ruby","sql-injection","validation","will-paginate","willpaginate"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sshaw.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-03-18T02:56:06.000Z","updated_at":"2025-06-21T03:00:51.000Z","dependencies_parsed_at":"2025-07-23T06:02:40.255Z","dependency_job_id":"a0455f64-ab86-4253-adcb-9f2ecf7a5c3a","html_url":"https://github.com/sshaw/page_number","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/sshaw/page_number","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Fpage_number","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Fpage_number/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Fpage_number/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Fpage_number/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sshaw","download_url":"https://codeload.github.com/sshaw/page_number/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Fpage_number/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274848186,"owners_count":25360981,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-12T02:00:09.324Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kaminari","pagination","ruby","sql-injection","validation","will-paginate","willpaginate"],"created_at":"2024-10-09T18:53:40.721Z","updated_at":"2025-09-12T17:42:04.144Z","avatar_url":"https://github.com/sshaw.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PageNumber\n\n[![CI](https://github.com/sshaw/page_number/actions/workflows/ci.yml/badge.svg)](https://github.com/sshaw/page_number/actions/workflows/ci.yml)\n\nUtility methods for pagination page and per page that make sure you'll\nalways have a valid number.\n\nUse them your controllers (recommended) or model or anywhere where you process page\ninfo.\n\n## Usage\n\n`PageNumber` provides 3 methods:\n\n* `page(n)`/`__page__(n)` (defaults to `1`)\n* `page!(n)`/`__page__!(n)` (raises `PageNumber::PageInvalid` instead of returning default)\n* `per_page(n)`/`__per_page__(n)` (defaults to `10`)\n\nTo use, `include` or `extend` the `PageNumber` module:\n\n```rb\nrequire \"page_number\"\n\nclass BaseController\n  include PageNumber\nend\n\nclass SubController \u003c BaseController\n  def index\n    User.all(:page =\u003e page(params[:page]), :per_page =\u003e per_page(params[:per_page]))\n  end\nend\n\n```\n\nTo have better control over how `page` and `per_page` work you can\ndefine one or more of the following methods:\n\n```rb\nclass BaseController\n  include PageNumber\n\n  # These are all optional\n  protected\n\n  def page_sizes\n    [ 25, 50, 100 ]\n  end\n\n  def default_per_page\n    20\n  end\n\n  def default_page\n    2\n  end\n\n  def max_page_number\n    # who knows!?\n  end\n```\n\n### will_paginate \u0026 ActiveRecord Subclasses\n\nIf you use `PageNumber` in a class context in model that uses will_paginate _and you subclasses_ that model you may receive the following error:\n```\nArgumentError: wrong number of arguments (given 0, expected 1)\n\tfrom /Users/sshaw/code/ruby/page_number/lib/page_number.rb:53:in `per_page'\n   \tfrom /Users/sshaw/.rvm/gems/ruby-2.3.7/gems/will_paginate-3.1.6/lib/will_paginate/per_page.rb:18:in `inherited'\n    ...\n```\n\nThis is because will_paginate is expecting its `per_page` method.\n\nOne way to avoid this:\n```rb\nclass YourModel \u003c ApplicationRecord\n  Pager = Class.new { extend PageNumber }\nend\n```\nNow instead of calling `PageNumber`'s `per_page` as is you call via the `Pager` class: `Pager.per_page`\n\n## Author\n\nSkye Shaw [skye.shaw AT gmail.com]\n\n## License\n\nReleased under the MIT License: http://www.opensource.org/licenses/MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshaw%2Fpage_number","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsshaw%2Fpage_number","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshaw%2Fpage_number/lists"}