Pagy:如何在页面之间保持一致的循环索引?

Pagy : How to keep consistent loop index across pages?

我通过类似

的postgres查询得到一个pg结果
  ActiveRecord::Base.transaction do
    ActiveRecord::Base.connection.execute(distance_sql)
  end

还有一些变量

ids = result.column_values(1)
@kms = result.column_values(6)
towns = Town.find(ids)
@pagy, @towns = pagy_array(towns, items: 18)

和我的循环

<% @towns.each_with_index do |town, idx| %>
  <%= town.name %> - <%= @kms[idx] %>
<% end %>

如何在页面之间保持一致的循环索引?

只需将循环替换为:

<% @towns.each.with_index(@pagy.offset) do |poi, idx| %>