当用户登陆只有 1 个结果的页面时,page[size] 从 10 更新为 1

page[size] getting updated from 10 to 1 when user lands on a page with only 1 result

#app/serializers/admin_serializer.rb
class AdminSerializer < ActiveModel::Serializer
  attributes :id, :email, :access_locked?
end


#app/controllers/dashboard/admins_controller.rb
def index
    @search = Admin.search(params[:q])
    if params[:page]
      @admins = @search.result(:distinct => true).page(params[:page][:number]).per(params[:page][:size])
    else
      @admins = @search.result(:distinct => true).page(1).per(10)
    end
    respond_to do |format|
      format.html
      format.json {render json: @admins}
    end
end

在访问 http://dashboard.localhost.com:3000/admins.json 时,我得到正确的 links,page[size] 参数为 10。后续页面只有一个管理对象要显示

"links": {
    "self": "http://dashboard.localhost.com:3000/admins.json?page%5Bnumber%5D=1&page%5Bsize%5D=10",
    "next": "http://dashboard.localhost.com:3000/admins.json?page%5Bnumber%5D=2&page%5Bsize%5D=10",
    "last": "http://dashboard.localhost.com:3000/admins.json?page%5Bnumber%5D=5&page%5Bsize%5D=10"
  }

但是如果我在这里访问最后一个 link 即 http://dashboard.localhost.com:3000/admins.json?page%5Bnumber%5D=5&page%5Bsize%5D=10 随后的 JSON 包含以下不正确的 links,其中 page[size] 参数为 1。由于此页面只有一个管理对象要显示,因此所有其他 links 生成包含 page[size]=1

"links": {
    "self": "http://dashboard.localhost.com:3000/admins.json?page%5Bnumber%5D=5&page%5Bsize%5D=10",
    "first": "http://dashboard.localhost.com:3000/admins.json?page%5Bnumber%5D=1&page%5Bsize%5D=10",
    "prev": "http://dashboard.localhost.com:3000/admins.json?page%5Bnumber%5D=4&page%5Bsize%5D=10"
  }

通过替换 @admins = @search.result(:distinct => true).page(params[:page][:number]).per(params[:page][:size]) 来自 @admins = @search.result(:distinct => true).page(params[:page][:number]).per(10)