2

could anyone help me get rid of the "item" element within "items

the output should be:
"list":{ "items":[ { { data1: "test" } , { data2: "test2" } } }

collection @list

child :items => :items do
  attributes :place_id
end

child :items do
  child :place do |place|
    extends 'places/place', object: place
  end
end

current output:
"list":{ "items":[{ "item":{data1: "test"} "item":{ data2: "test2"}}}

p.s.w.g
  • 146,324
  • 30
  • 291
  • 331
user896715
  • 101
  • 1
  • 6

3 Answers3

8

I had the same problem and this was the solution. You may need to create the file named to configure rabl.
config/initializers/rabl.config.rb

Rabl.configure do |config|
    config.include_json_root = true
    config.include_child_root =  false
end
Debbie
  • 136
  • 1
  • 6
1

Old question, for future users' reference:

Fire up the file rabl_init.rb, turn off root by config.include_json_root = false, if you still want a root in your collection objects, use something like:

collection @orders, :object_root=>"order"
    extends "api/v1/orders/show"
# End of @orders
Damon Aw
  • 4,722
  • 4
  • 28
  • 37
0

There's a working solution for removing the root elements in child nodes at: Removing child root nodes in RABL

Setting the config.include_json_root = false seems to remove only the first level root of the JSON.

Community
  • 1
  • 1
Gnomet
  • 966
  • 10
  • 12