RABL изменить имя корневого узла

У меня проблема с 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

Вывод при попадании в target.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": [
            {
                "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
                }
            }
        ]
    }

Обратите внимание на узлы «профиль» вместо узлов «цель».

Как мне этого добиться?


person botbot    schedule 12.02.2013    source источник


Ответы (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
person Pål    schedule 19.02.2013

Что-то вроде этого должно сработать... В настоящее время RABL больше не используется, но я его помню таким...

node :profile do 
  attributes :id, :username, :customer_id, :first_name, :last_name, :avatar_url
end
person thenamewasmilo    schedule 13.02.2013
comment
Это легко, я сменил работу :p Я бы использовал его снова в будущем, если бы он мне понадобился. - person thenamewasmilo; 14.02.2013