2

I have an index view with 45 products and 3 pages.

I'm using pagy_array like : @pagy, @products = pagy_array(products, items: 20)

If I delete 6 products, I get 39 items on 2 pages. But Google have indexed the third page, and when a customer come on this page, he get an error expected :page in 1..2; got 3

How can I compare the params[:page] to the @pagy.page and made a redirect 301 if bigger ?

Ben
  • 660
  • 5
  • 25

2 Answers2

4

Please check this documentation. You can configure this in the pagy.rb initialiser

https://ddnexus.github.io/pagy/extras/overflow

in the pagy.rb initializer:

require 'pagy/extras/overflow'

# default :empty_page (other options :last_page and :exception )
Pagy::VARS[:overflow] = :last_page

# OR
require 'pagy/countless'
require 'pagy/extras/overflow'

# default :empty_page (other option :exception )
Pagy::VARS[:overflow] = :exception

Other options for handling overflow - :last_page, :empty_page or :exception

Aarthi
  • 1,451
  • 15
  • 39
0

to fix it on current date 08/31/2023

in the pagy.rb initializer

#to return last available page

require "pagy/extras/overflow"

Pagy::DEFAULT[:overflow] = :last_page

#to return empty page

require "pagy/extras/overflow"

Pagy::DEFAULT[:overflow] = :empty_page