0

I have used Elastic Search to fetch the data and am trying to use Pagination gem to toggle between pages. But i am currently facing an issue in

<%= will_paginate @data %>

i am getting an error

NoMethodError - undefined method `total_pages' for #<Array:0x007fdcfbd3f128>

since @data is an array instead of an Active Record since the data was fetched from Elastic Search

Is there anyway to specify the total pages so that i will still be able to use the gem.

  • Using will paginate for array: https://stackoverflow.com/questions/4352895/ruby-on-rails-will-paginate-an-array https://makandracards.com/makandra/13521-will_paginate-can-paginate-plain-ruby-arrays – Deepesh Apr 17 '18 at 13:12

1 Answers1

0

Your @data is an array instead of collection so to use will_paginate on array you can do like this:

require 'will_paginate/array'

And then:

@data.paginate(:page => 2, :per_page => 10)

will work.

Source: https://github.com/mislav/will_paginate/wiki/Backwards-incompatibility#willpaginatecollection

Deepesh
  • 6,138
  • 1
  • 24
  • 41