Coder Social home page Coder Social logo

Comments (8)

kellyselden avatar kellyselden commented on June 19, 2024

The response needs to look like this:

{
  items: [
    {id: 1, name: 'Test'},
    {id: 2, name: 'Test 2'}
  ],
  meta: {
    total_pages: 3
  }
}

from ember-infinity.

szsoppa avatar szsoppa commented on June 19, 2024

Thank's for reply, works great now :)

from ember-infinity.

dja avatar dja commented on June 19, 2024

@szsoppa did you find a good solution for including the pages data in the JSON response under meta? I'm using headers now too, and can't find much on the backend with kaminari or grape on how to structure that properly.

from ember-infinity.

szsoppa avatar szsoppa commented on June 19, 2024

I used https://github.com/monterail/grape-kaminari gem to return all of the data required by ember-infinity. You can see in documentation that it's pretty simple to use.

from ember-infinity.

dja avatar dja commented on June 19, 2024

Thanks @szsoppa - I'm still not seeing where in grape-kaminari to tell it to include the total_pages in meta as part of the json response.. Is it conflicting with active_model_serializers perhaps?

from ember-infinity.

szsoppa avatar szsoppa commented on June 19, 2024

It may have a problem with active_model_serializers. As you can see here https://github.com/monterail/grape-kaminari/blob/master/lib/grape/kaminari.rb#L11 it should include this header out of the box. I used grape-entity gem to serialize data and it worked great.

from ember-infinity.

dja avatar dja commented on June 19, 2024

Found this https://github.com/ruby-grape/grape-active_model_serializers#custom-metadata to modify the Rails side, or this http://codeandtechno.com/posts/metadata-via-response-headers-in-emberjs/ to modify the Ember side. For anyone who might need it..

from ember-infinity.

rmcsharry avatar rmcsharry commented on June 19, 2024

Be aware that the default is "total_pages" with an underscore and you might be returning dasherized attribute names.

Also, the latest ASM includes links metadata by default, more here on that.

I had this issue and you can read more about it here.

My controller renders like this:

    render json: @employees, meta: { total: (Employee.count / params[:per_page].to_f).ceil }

from ember-infinity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.