IcaliaLabs / pager-api

Easy API pagination for Rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Metadata not appearing

hewrin opened this issue · comments

commented

Hi, I'm using this gem to communicate with an iOS app, my config is as so

PagerApi.setup do |config|

  # Pagination Handler
  # User this option to meet your pagination handler, whether is :kaminari or :will_paginate
  config.pagination_handler = :kaminari

  # Includes Pagination information on Meta
  #
  config.include_pagination_on_meta = true

  # Includes Pagination information on a Link Header
  #
  config.include_pagination_headers = true

  # Set the Total-Count Header name
  config.total_count_header = "X-Total-Count"
end

and I 'm using it like so in my controllers

def index paginate Registration.all, per_page: 1 end

The response I get is as below

[ { "paid_at" : null, "status" : "pending", "sponsorship_id" : null, "user_id" : 1, "course_id" : 1, "updated_at" : "2016-06-01T10:39:34.262+08:00", "transaction_id" : null, "fees_paid_cents" : 0, "referrer_id" : null, "graduate_status" : "not_graduated", "payment_method" : null, "total_paid_cents" : 0, "tax_paid_cents" : 0, "id" : "c0d47566-f5b3-4217-81df-79ef3bb8267f", "book_entry_record_url" : "https:\/\/sg.qbo.intuit.com\/app\/salesreceipt?txnId=", "referrer_paid_at" : null, "referrer_transaction_id" : null, "created_at" : "2016-06-01T10:39:34.262+08:00", "total_paid_currency" : "MYR", "tax_paid_currency" : "MYR", "fees_paid_currency" : "MYR" } ] [ { "paid_at" : null, "status" : "pending", "sponsorship_id" : null, "user_id" : 1, "course_id" : 1, "updated_at" : "2016-06-01T10:39:34.262+08:00", "transaction_id" : null, "fees_paid_cents" : 0, "referrer_id" : null, "graduate_status" : "not_graduated", "payment_method" : null, "total_paid_cents" : 0, "tax_paid_cents" : 0, "id" : "c0d47566-f5b3-4217-81df-79ef3bb8267f", "book_entry_record_url" : "https:\/\/sg.qbo.intuit.com\/app\/salesreceipt?txnId=", "referrer_paid_at" : null, "referrer_transaction_id" : null, "created_at" : "2016-06-01T10:39:34.262+08:00", "total_paid_currency" : "MYR", "tax_paid_currency" : "MYR", "fees_paid_currency" : "MYR" }, { "paid_at" : null, "status" : "pending", "sponsorship_id" : null, "user_id" : 2, "course_id" : 1, "updated_at" : "2016-06-01T10:39:34.337+08:00", "transaction_id" : null, "fees_paid_cents" : 0, "referrer_id" : null, "graduate_status" : "not_graduated", "payment_method" : null, "total_paid_cents" : 0, "tax_paid_cents" : 0, "id" : "2e0050ec-2e37-4a85-88b4-86c63c9a829d", "book_entry_record_url" : "https:\/\/sg.qbo.intuit.com\/app\/salesreceipt?txnId=", "referrer_paid_at" : null, "referrer_transaction_id" : null, "created_at" : "2016-06-01T10:39:34.337+08:00", "total_paid_currency" : "MYR", "tax_paid_currency" : "MYR", "fees_paid_currency" : "MYR" }, { "paid_at" : null, "status" : "pending", "sponsorship_id" : null, "user_id" : 3, "course_id" : 1, "updated_at" : "2016-06-01T10:39:34.361+08:00", "transaction_id" : null, "fees_paid_cents" : 0, "referrer_id" : null, "graduate_status" : "not_graduated", "payment_method" : null, "total_paid_cents" : 0, "tax_paid_cents" : 0, "id" : "a9c49040-efb5-42f5-ba44-a92020cd8c22", "book_entry_record_url" : "https:\/\/sg.qbo.intuit.com\/app\/salesreceipt?txnId=", "referrer_paid_at" : null, "referrer_transaction_id" : null, "created_at" : "2016-06-01T10:39:34.361+08:00", "total_paid_currency" : "MYR", "tax_paid_currency" : "MYR", "fees_paid_currency" : "MYR" }, { "paid_at" : null, "status" : "pending", "sponsorship_id" : 1, "user_id" : 4, "course_id" : 1, "updated_at" : "2016-06-01T10:39:34.386+08:00", "transaction_id" : null, "fees_paid_cents" : 0, "referrer_id" : null, "graduate_status" : "not_graduated", "payment_method" : null, "total_paid_cents" : 0, "tax_paid_cents" : 0, "id" : "5d7cd71f-4522-45de-974c-a7748918f377", "book_entry_record_url" : "https:\/\/sg.qbo.intuit.com\/app\/salesreceipt?txnId=", "referrer_paid_at" : null, "referrer_transaction_id" : null, "created_at" : "2016-06-01T10:39:34.386+08:00", "total_paid_currency" : "MYR", "tax_paid_currency" : "MYR", "fees_paid_currency" : "MYR" }, { "paid_at" : null, "status" : "pending", "sponsorship_id" : null, "user_id" : 5, "course_id" : 1, "updated_at" : "2016-06-01T10:39:34.411+08:00", "transaction_id" : null, "fees_paid_cents" : 0, "referrer_id" : null, "graduate_status" : "not_graduated", "payment_method" : null, "total_paid_cents" : 0, "tax_paid_cents" : 0, "id" : "3eb2f267-38ed-462a-aa2a-875a3e95e0db", "book_entry_record_url" : "https:\/\/sg.qbo.intuit.com\/app\/salesreceipt?txnId=", "referrer_paid_at" : null, "referrer_transaction_id" : null, "created_at" : "2016-06-01T10:39:34.411+08:00", "total_paid_currency" : "MYR", "tax_paid_currency" : "MYR", "fees_paid_currency" : "MYR" }, { "paid_at" : null, "status" : "pending", "sponsorship_id" : null, "user_id" : 6, "course_id" : 1, "updated_at" : "2016-06-01T10:39:34.433+08:00", "transaction_id" : null, "fees_paid_cents" : 0, "referrer_id" : null, "graduate_status" : "not_graduated", "payment_method" : null, "total_paid_cents" : 0, "tax_paid_cents" : 0, "id" : "9d96a727-f274-4586-973e-be477130ef26", "book_entry_record_url" : "https:\/\/sg.qbo.intuit.com\/app\/salesreceipt?txnId=", "referrer_paid_at" : null, "referrer_transaction_id" : null, "created_at" : "2016-06-01T10:39:34.433+08:00", "total_paid_currency" : "MYR", "tax_paid_currency" : "MYR", "fees_paid_currency" : "MYR" }, { "paid_at" : null, "status" : "pending", "sponsorship_id" : null, "user_id" : 8, "course_id" : 1, "updated_at" : "2016-06-01T10:39:34.470+08:00", "transaction_id" : null, "fees_paid_cents" : 0, "referrer_id" : null, "graduate_status" : "not_graduated", "payment_method" : null, "total_paid_cents" : 0, "tax_paid_cents" : 0, "id" : "0ee9c953-64a0-4647-96e9-274cfa7f6a50", "book_entry_record_url" : "https:\/\/sg.qbo.intuit.com\/app\/salesreceipt?txnId=", "referrer_paid_at" : null, "referrer_transaction_id" : null, "created_at" : "2016-06-01T10:39:34.470+08:00", "total_paid_currency" : "MYR", "tax_paid_currency" : "MYR", "fees_paid_currency" : "MYR" }, { "paid_at" : null, "status" : "pending", "sponsorship_id" : null, "user_id" : 9, "course_id" : 1, "updated_at" : "2016-06-01T10:39:34.493+08:00", "transaction_id" : null, "fees_paid_cents" : 0, "referrer_id" : null, "graduate_status" : "not_graduated", "payment_method" : null, "total_paid_cents" : 0, "tax_paid_cents" : 0, "id" : "5ce71f97-84dc-42bf-872a-ce6f483de19e", "book_entry_record_url" : "https:\/\/sg.qbo.intuit.com\/app\/salesreceipt?txnId=", "referrer_paid_at" : null, "referrer_transaction_id" : null, "created_at" : "2016-06-01T10:39:34.493+08:00", "total_paid_currency" : "MYR", "tax_paid_currency" : "MYR", "fees_paid_currency" : "MYR" }, { "paid_at" : null, "status" : "pending", "sponsorship_id" : null, "user_id" : 10, "course_id" : 1, "updated_at" : "2016-06-01T10:39:34.518+08:00", "transaction_id" : null, "fees_paid_cents" : 0, "referrer_id" : null, "graduate_status" : "not_graduated", "payment_method" : null, "total_paid_cents" : 0, "tax_paid_cents" : 0, "id" : "f2de4b51-24a4-4628-b144-bf386bc27ac5", "book_entry_record_url" : "https:\/\/sg.qbo.intuit.com\/app\/salesreceipt?txnId=", "referrer_paid_at" : null, "referrer_transaction_id" : null, "created_at" : "2016-06-01T10:39:34.518+08:00", "total_paid_currency" : "MYR", "tax_paid_currency" : "MYR", "fees_paid_currency" : "MYR" }, { "paid_at" : null, "status" : "pending", "sponsorship_id" : null, "user_id" : 11, "course_id" : 1, "updated_at" : "2016-06-01T10:39:34.542+08:00", "transaction_id" : null, "fees_paid_cents" : 0, "referrer_id" : null, "graduate_status" : "not_graduated", "payment_method" : null, "total_paid_cents" : 0, "tax_paid_cents" : 0, "id" : "9917b6c7-57cd-4ef9-968c-d9feaf0b24d4", "book_entry_record_url" : "https:\/\/sg.qbo.intuit.com\/app\/salesreceipt?txnId=", "referrer_paid_at" : null, "referrer_transaction_id" : null, "created_at" : "2016-06-01T10:39:34.542+08:00", "total_paid_currency" : "MYR", "tax_paid_currency" : "MYR", "fees_paid_currency" : "MYR" } ]

I cant get the metadata to appear.
I noticed changing the paginate method in kaminari.rb from render options to return options makes it work.

I've got the same problem - JSON is rendered OK, but nothing will appear in the headers.

Let me take a look, I'll come back with you

I noticed changing the paginate method in kaminari.rb from render options to return options makes it work

i installed your repo and it doesn't work, i got a response with status 204 (no content)

@michalvalasek Are you using active model serializers?

@kurenn Yes, I am.

Have you take a look at @BrahimDahmani solution?

I'm facing the same issue as @michalvalasek . Is this gem still being maintained?

@estebanbouza give this a try!

gem 'pager_api' , :github => 'BrahimDahmani/pager-api', :branch => "bugfixes"

It has been merged now, the new gem version is 0.2.1 please read the documentation for the update on active model serializers 0.10 and let me know how it goes!

Meta is still not returned with response in the latest version 0.2.1. Not using AMS. render json: options from @BrahimDahmani 's fork works though, but you seem to have removed it again in 53cc6b1

@thomey I will check cause with AMS seems to be breaking if I leave the render json: ... statement...have you tried it out?

Unfortunately I dropped your gem because I couldn't get it working with grape. Kept getting "Undefined method 'paginate'". It maybe has to do with ActionController and how you do the includes, but I didn't have time to dig deeper so I'm just using grape-kaminari and get the pagination meta from the headers instead. ;)