问题
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"}}}
回答1:
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
回答2:
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
回答3:
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.
来源:https://stackoverflow.com/questions/10109963/rabl-remove-parent-element-of-children