1

我在更改嵌套节点名称时遇到了 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
                }
            }
        ]
    }

请注意“配置文件”节点而不是“目标”节点。

我如何实现这一目标?

4

2 回答 2

2

我认为这也应该有效。在targets/index.json.rabl中输入:

collection @customers => :targets

child :profile do
  extends 'customers/profile'
end

customers/profile.json.rabl中:

object @profile
attributes :id, :username, :customer_id, :first_name, :last_name, :avatar_url
于 2013-02-19T14:54:54.217 回答
0

像这样的东西应该可以工作......目前不再使用RABL,但这就是我记得的......

node :profile do 
  attributes :id, :username, :customer_id, :first_name, :last_name, :avatar_url
end
于 2013-02-13T12:44:08.510 回答