0

I have hash that have values in form of array. i am using will paginate for pagination. But recieve error

           "undefined method paginate for Hash". 

below is my code

   h = {"127.1.0"=>[31.553965003401203, 74.35798642106394], "127.2.0"=>[54.99947245294339, 74.35810745776595], "127.0.0"=>[51.07178714109552, 71.86443937665145]}

   h.paginate(:page => params[:page], :per_page => 30) #giving error

Any help to done this...

Kashiftufail
  • 10,815
  • 11
  • 45
  • 79
  • Have you tried `will_paginate(h)`? It looks like (from the (docs)[https://github.com/mislav/will_paginate/wiki/API-documentation]) that you can paginate collections (non ActiveRecord) objects that way. I'm not sure what the links will give you since the hash doesn't have an implicit "link" generator. But that might work. – mr rogers Jan 24 '15 at 17:34
  • Not working for me.................. – Kashiftufail Jan 24 '15 at 17:38

1 Answers1

2

It looks like you can use the will_paginate/array module which would at least get you paginating on an array. Try something like this.

require 'will_paginate/array'
h = {"127.1.0"=>[31.553965003401203, 74.35798642106394], "127.2.0"=>[54.99947245294339, 74.35810745776595], "127.0.0"=>[51.07178714109552, 71.86443937665145] }
h.keys.paginate(page: params[:page], per_page: 30)

(similar to Ruby on Rails will_paginate an array)

Community
  • 1
  • 1
mr rogers
  • 3,200
  • 1
  • 19
  • 31