2

I am building a Rails 3.2 app and I am using Rabl templates. I would like to add a "root node" that displays the total number of records. The solution below adds the total node to each record. I want it on top of all records.

collection @projects

extends "projects/_base"

node(:total_entries) { @projects.total_count }

I want it to be like this:

- total_entries: 3
-- Entry 1
-- Entry 2
-- Entry 3
Jonathan Clark
  • 19,726
  • 29
  • 111
  • 175

1 Answers1

0

From an example in the README:

object false
node(:total_entries) { @foos.count }
child(@foos, :object_root => false) { attributes :name }

=>

{
  "total_entries": 2,
  "foos": [
    {
      "name": "Jane"
    },
    {
      "name": "John"
    }
  ]
}

Or don't set the object_root in to generate:

{
  "total_entries": 2,
  "foos": [
    {
      "foo": {
        "name": "Jane"
      }
    },
    {
      "foo": {
        "name": "John"
      }
    }
  ]
}
phillbaker
  • 1,518
  • 11
  • 22