Paginating an Array in Ruby with will_paginate

前端 未结 5 1579
耶瑟儿~
耶瑟儿~ 2020-11-27 16:56

I have an array @level1 which looks like this :

[[3.0, 4, 2], [2.0, 48, 3], [2.1, 56, 4], ............]

I want to apply pagination on this

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-27 17:23

    Sure, you can use WillPaginate::Collection to construct arbitrary pagination across collections. Assuming an array called values:

    @values = WillPaginate::Collection.create(current_page, per_page, values.length) do |pager|
      pager.replace values
    end
    

    You can then treat @values just like any other WillPaginate collection, including passing it to the will_paginate view helper.

提交回复
热议问题