Mr_Nizzle
Mr_Nizzle

Reputation: 6714

How to show json root for object in rabl when config.include_json_root = false

I'm using the rabl gem in my rails API and at the beginning I set config.include_json_root = false and I've been working without the root of the json response but now I have a new resource and just in that resource I need to get the root.

I was trying something like:

object @myobj, :root => 'foo'

But that's not working at all.

How can I add the json root only to this rabl file and leave everything else without any modification?

Upvotes: 1

Views: 881

Answers (2)

Pop-A-Stash
Pop-A-Stash

Reputation: 6652

Try this:

object false
child(@myobj) { 
  attribute :attr1 :attr2
}

I was scratching my head for a minute until someone pointed this out to me.

Upvotes: 1

Brett Allred
Brett Allred

Reputation: 3487

node(:foo) do |myobj|
      {
        :apy => myobj.apy,
        :apr => myobj.apr
      }
end

Upvotes: 0

Related Questions