Paginating an Array in Ruby with will_paginate

前端 未结 5 1580
耶瑟儿~
耶瑟儿~ 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条回答
  •  忘掉有多难
    2020-11-27 17:09

    This is my example based in the answer of @chris-heald

    products = %w(i love ruby on rails)
    @products = WillPaginate::Collection.create(params[:page], params[:per_page], products.length) do |pager|
       pager.replace products[pager.offset, pager.per_page]
    end
    

提交回复
热议问题