no total_pages in meta response
See original GitHub issueHello,
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:
- Created 9 years ago
- Comments:8 (2 by maintainers)
Top GitHub Comments
@shanekoss I’m using Rails 5.0 with Active Model Serializers and
kaminari
for pagination on the backend side, as well as the ordinaryJSONAPIAdapter
on the frontend side. Changingtotal_pages
tototal-pages
should work just as you see it in the first post of this thread. Here’s some code for a model calledstatistic/broadcast
:@shanekoss
Unfortunately, I haven’t used AMD (or Rails) in a while so I do not recall the specifics.
Sorry I couldn’t help