About Me

My photo
जिंदगी की परीक्षा में कोई नम्बर नहीं मिलते है लोग आपको दिल से याद करे तो समझ लेना आप पास हो गए....

Thursday 11 October 2012

How to use will paginate with array of hashes




Suppose we have an object  which is having value as array of hashes (In example @student['results'] is an array of hashes which is returned from some API call)

so the is given below

  @students = WillPaginate::Collection.create(@page, @page_size) do |pager|
        # inject the result array into the paginated collection:
        pager.replace(@student['results'])
        unless pager.total_entries
          # the pager didn't manage to guess the total count, do it manually
          pager.total_entries = (@student['total_pages'] * @page_size)
        end
      end

No comments:

Post a Comment