{"record":{"id":"2f0399918719759e","repo":"mislav/will_paginate","slug":"page-parameter-required","errorCode":null,"errorMessage":":page parameter required","messagePattern":":page parameter required","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/will_paginate/active_record.rb","lineNumber":145,"sourceCode":"            col.replace super\n            col.total_entries ||= total_entries\n          end\n        end\n      end\n\n      private\n\n      def copy_will_paginate_data(other)\n        other.current_page = current_page unless other.current_page\n        other.total_entries = nil if defined? @total_entries_queried\n        other\n      end\n    end\n\n    module Pagination\n      def paginate(options)\n        options  = options.dup\n        pagenum  = options.fetch(:page) { raise ArgumentError, \":page parameter required\" }\n        options.delete(:page)\n        per_page = options.delete(:per_page) || self.per_page\n        total    = options.delete(:total_entries)\n\n        if options.any?\n          raise ArgumentError, \"unsupported parameters: %p\" % options.keys\n        end\n\n        rel = limit(per_page.to_i).page(pagenum)\n        rel.total_entries = total.to_i          unless total.blank?\n        rel\n      end\n\n      def page(num)\n        rel = if ::ActiveRecord::Relation === self\n          self\n        elsif !defined?(::ActiveRecord::Scoping) or ::ActiveRecord::Scoping::ClassMethods.method_defined? :with_scope\n          # Active Record 3","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/mislav/will_paginate/blob/50017c3eb0712e7b3a53268a81e81a184b7a49f6/lib/will_paginate/active_record.rb#L127-L163","documentation":"ActiveRecord::Relation#paginate (the Pagination module that will_paginate mixes into models/relations) requires a :page key in its options hash. The implementation calls options.fetch(:page) with a raise-on-missing block, so ArgumentError ':page parameter required' is thrown the moment the :page key is absent. It is the library's way of refusing to build a paged relation when the caller never said which page to load.","triggerScenarios":"Calling Model.paginate(per_page: 10), Model.paginate(:per_page => 10, :total_entries => 42), or relation.paginate(...) with no :page key at all. Note the asymmetry: paginate(page: nil) does NOT raise here (nil is later coerced to page 1 by the page scope); only key absence triggers it.","commonSituations":"Porting old AR2-era sample code that relied on a default page; forwarding a params hash that was sliced/excepted and lost :page; test/spec helpers that call paginate directly without page; refactoring away from Model.page(num) and forgetting the option lives inside the paginate hash.","solutions":["Pass an explicit page with a sane default: Model.paginate(page: params[:page] || 1, per_page: 10)","Prefer the scope chain instead: Model.page(params[:page] || 1).per(10) — the page() scope never raises on a missing argument the way paginate() does","If you never intended pagination, drop paginate and use limit/where directly"],"exampleFix":"// before\n@posts = Post.paginate(per_page: 10)\n\n// after\n@posts = Post.paginate(page: params[:page] || 1, per_page: 10)","handlingStrategy":"validation","validationCode":"# before calling paginate, guarantee the :page key exists with a default\nopts = { page: 1 }.merge(options.symbolize_keys)\nraise ArgumentError, ':page parameter required' unless opts.key?(:page)\n@posts = Post.where(...).paginate(opts)","typeGuard":null,"tryCatchPattern":"begin\n  @posts = Post.paginate(options)\nrescue ArgumentError => e\n  raise unless e.message == ':page parameter required'\n  @posts = Post.paginate(options.merge(page: 1))\nend","preventionTips":["Centralize pagination params in one controller helper: def page_param = params[:page] || 1, and use it at every paginate call site","Prefer the page(...).per(...) scope chain over paginate in new code — it degrades gracefully on nil/missing page","Add a spec that exercises each list action with an empty params hash to catch missing :page before production"],"tags":["will-paginate","activerecord","argument-error","pagination"],"backgroundTag":"missing-required-parameter","analyzedSha":"50017c3eb0712e7b3a53268a81e81a184b7a49f6","analyzedAt":"2026-08-21T19:50:58.546Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}