在RABL中删除子根节点 [英] Removing child root nodes in RABL
本文介绍了在RABL中删除子根节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用RABL渲染一个非常简单的数据结构,但是我不知道如何正确删除子根节点.这是我的两个模板.
I'm trying to render a pretty simple data structure using RABL, but I can't figure out how to remove the child root nodes properly. Here are my two templates.
首先是集合索引模板.
collection @groups, :object_root => false
attributes :id, :name
child :files do
extends 'groups/_file'
end
然后是文件部分模板.
object @file
attributes :id
这两个模板最终产生以下JSON:
Those two templates end up producing the following JSON:
[
{
"id":"4f57bf67f85544e620000001",
"name":"Some Group",
"files":[
{
"file":{
"id":"4f5aa3fef855441009000007"
}
}
]
}
]
我想找到一种方法来删除文件集合中的根文件"键.像这样:
I want to find a way to remove the root "file" key inside of the files collection. Something like:
[
{
"id":"4f57bf67f85544e620000001",
"name":"Some Group",
"files":[
{
"id":"4f5aa3fef855441009000007"
}
]
}
]
推荐答案
在最新版本的Rabl中,如果希望所有级别的include_root_json
都为false
,则必须设置此配置.
On latest versions of Rabl, you have to set this configuration if you want include_root_json
to be false
in all levels.
Rabl.configure do |config|
config.include_json_root = false
config.include_child_root = false
end
这篇关于在RABL中删除子根节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文