question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no total_pages in meta response

See original GitHub issue

Hello,

First, I must say that this library is pretty cool and is a big help in getting set up with some new Ember projects I’m working on.

Unfortunately, I am receiving some errors when trying to use a model with a DS.ActiveModelAdapter backend.

Just for reference here is some code:

// adapters/application.js
import DS from 'ember-data';

export default DS.ActiveModelAdapter.extend({
  namespace: 'api',
  host: 'http://localhost:3000'
});
// controllers/users.js
import Ember from 'ember';

export default Ember.ArrayController.extend({
  queryParams: ['page', 'perPage'],
  pageBinding: 'model.page',
  perPageBinding: 'model.perPage',
  totalPagesBinding: 'model.totalPages',
  page: 1,
  perPage: 20
});
// /models/user.js
import DS from 'ember-data';

export default DS.Model.extend({
  lastName: DS.attr('string'),
  firstName: DS.attr('string'),
  email: DS.attr('string'),
  clockEvents: DS.hasMany('clock-event')
});
// /routes/users.js
import Ember from 'ember';

import RouteMixin from 'ember-cli-pagination/remote/route-mixin';

export default Ember.Route.extend(RouteMixin, {
  perPage: 20,
  model: function(params) {
    params.paramMapping = {
      page: 'page',
      perPage: 'per_page',
      total_pages: 'Total-Pages'
    };
    return this.findPaged('user', params);
  }
});

In my users template I am able to iterate over the paged array of users and I set a paginator with:

{{page-numbers content=model

It is able to get the current page and show arrows, however the “next” arrow is grayed out (though I can still click on it). In the console I have a number of warnings:

ember.js:15373 no total_pages in meta response
ember.js:15373 Object {}
ember.js:15373 no totalPages for page-numbers
ember.js:15373 no int for totalPages val is undefined
ember.js:15373 no int for totalPages val is NaN
9ember.js:15373 no int for totalPages val is NaN

Here are some sample headers in the response from my API server:

Access-Control-Allow-Credentials:true
Access-Control-Allow-Methods:GET, POST, OPTIONS, PUT, DELETE
Access-Control-Allow-Origin:http://localhost:4200
Access-Control-Expose-Headers:
Access-Control-Max-Age:1728000
Cache-Control:max-age=0, private, must-revalidate
Connection:Keep-Alive
Date:Mon, 12 Jan 2015 20:25:13 GMT
Etag:W/"653880d357c59f060b877659a7ea3213"
Next-Page:2
Offset:0
Page:1
Per-Page:20
Prev-Page:
Server:WEBrick/1.3.1 (Ruby/2.2.0/2014-12-25)
Total:149
Total-Pages:8
Vary:Origin
X-Request-Id:dfa3771e-dc5d-4496-8748-8f8c9b3fe5ee
X-Runtime:0.045344

Originally the pagination stuff had X- prefixes, but it didn’t work so I tried removing the prefix to see if it would improve the situation but it doesn’t seem to have.

The params.paramsMapping seems to have an affect for the perPage but I don’t think it’s working for the total_pages part.

If anyone can point me in the right direction or give me some advice I’d greatly appreciate it. I am still very new to Ember so I might be missing something obvious.

Thanks!

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
roschaefercommented, Mar 7, 2018

@shanekoss I’m using Rails 5.0 with Active Model Serializers and kaminari for pagination on the backend side, as well as the ordinary JSONAPIAdapter on the frontend side. Changing total_pages to total-pages should work just as you see it in the first post of this thread. Here’s some code for a model called statistic/broadcast:

  model: function(params) {
    params.paramMapping = {
      total_pages: "total-pages"
    };
    return this.findPaged('statistic/broadcast', params);
}
1reaction
mylanconnollycommented, Mar 7, 2018

@shanekoss

Unfortunately, I haven’t used AMD (or Rails) in a while so I do not recall the specifics.

Sorry I couldn’t help

Read more comments on GitHub >

github_iconTop Results From Across the Web

no total_pages in meta response · Issue #206 - GitHub
Hello, My api send me this structure {"users": [ ... ], "meta": { "pagination": { "total":6, "count":6, "per_page":10, "current_page":1, ...
Read more >
Get totalPages of response - java - Stack Overflow
My question is how to get the totalPages out of the response easily. The problem is, that the meta-data of the response is...
Read more >
Paging in ASP.NET Core Web API - Code Maze
In this article, we're going to learn how to implement paging in ASP.NET Core Web API project with detailed examples and improvements.
Read more >
REST Pagination in Spring - Baeldung
Pagination in a Spring REST Service - URI structure and best practice, Page as Resource vs Page as Representation.
Read more >
“Cursor Pagination” Profile - JSON:API
If their value is not a valid cursor, the server MUST respond according to the rules ... metadata to indicate to the client...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found