gpt4 book ai didi

ruby-on-rails - Searchkick分页,限制和偏移问题,滑轨

转载 作者:行者123 更新时间:2023-12-03 02:12:43 25 4
gpt4 key购买 nike

我想在第一行显示3个最后的外观,然后我要显示所有其他但没有3个最后的外观。
这是我的代码

def index
query = params[:query].presence || "*"
conditions = {}
conditions[:available] = true
conditions[:look_tags] = params[:look_tags] if params[:look_tags].present?
@last_3_looks = Look.search query, where: conditions, order: { created_at: :desc }, limit: 3
@looks = Look.search query, where: conditions, order: { created_at: :desc }, page: params[:page], per_page: 8
end
问题是如果我像下面这样放置偏移量,我在每页上都有相同的8个外观,请问如何处理?
@looks = Look.search query, where: conditions, order: { created_at: :desc }, page: params[:page], per_page: 8, offset: 3
end

最佳答案

好像您要计算偏移量,例如:

  page = params[:page].to_i
per_page = 8
starting_offset = 3
offset = starting_offset + ((page - 1) * per_page)

@looks = Look.search query, where: conditions, order: { created_at: :desc }, page: page, per_page: per_page, offset: offset
但是您也可以考虑使用 kaminari gem,它将为您进行计算。
看起来像Searchkick allows that
另外,请参阅此 answers

关于ruby-on-rails - Searchkick分页,限制和偏移问题,滑轨,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64276539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com