Coder Social home page Coder Social logo

use array instead of hash about rabl HOT 6 CLOSED

nesquena avatar nesquena commented on July 19, 2024
use array instead of hash

from rabl.

Comments (6)

nesquena avatar nesquena commented on July 19, 2024

Array is the root object only for collections

Rabl.configure do |config|
  config.include_json_root = false
end

then all the objects (in collections) will not include the root node and start as arrays. Is that what you mean?

from rabl.

wtn avatar wtn commented on July 19, 2024

Is there's a way to construct [[]] with rabl?

from rabl.

nesquena avatar nesquena commented on July 19, 2024

Can you give me an example of the type of data response you want to generate?

from rabl.

joerodriguez avatar joerodriguez commented on July 19, 2024

Also having a bit of trouble getting rabl to return something like:

[{ "name": "Joe", "age": 22 }, { "name": "Michael", "age": 26 }]

Let's say my controller has an instance variable named @people

from rabl.

nesquena avatar nesquena commented on July 19, 2024

Take a look at configuration options. By default rabl assumes you want 'json' roots which is to say

[{ "person" : { "name": "Joe", "age": 22 } }, { "person" : { "name": "Michael", "age": 26  } }]

since this is what mirrors rails most closely and it's generally a better pattern to have a way to recognize the data contained in the dictionary. You can play with config.include_json_root (check the readme) to change that behavior throughout an application.

from rabl.

nesquena avatar nesquena commented on July 19, 2024

This should be fixed with config.include_json_root options

from rabl.

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.