我在更改嵌套节点名称时遇到了 rabl 问题:
例如,这是我的目标/index.json.rabl
collection @customers => :targets
extends 'customers/profile'
这是我的客户/profile.json.rabl
object @customer => :profile
attributes :id, :username, :customer_id, :first_name, :last_name, :avatar_url
命中targets.json(targets#index)时的输出:
{
"targets": [
{
"target": {
"id": 3,
"username": null,
"first_name": "Scott",
"last_name": "Thomas",
"avatar_url": null
}
},
{
"target": {
"id": 3,
"username": null,
"first_name": "Thomas",
"last_name": "MacKay",
"avatar_url": null
}
}
]
}
问题是我希望“targets”数组中的“target”节点被命名为“profile”。像这样:
{
"targets": [
{
"profile": {
"id": 3,
"username": null,
"first_name": "Scott",
"last_name": "Thomas",
"avatar_url": null
}
},
{
"profile": {
"id": 3,
"username": null,
"first_name": "Thomas",
"last_name": "MacKay",
"avatar_url": null
}
}
]
}
请注意“配置文件”节点而不是“目标”节点。
我如何实现这一目标?