我得到一个带有 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 %>
如何在页面之间保持一致的循环索引?