1
votes

I'm having an issue with rabl where it is changing the nested node names:

Example, here is my targets/index.json.rabl

collection @customers => :targets
extends 'customers/profile'

And here is my customers/profile.json.rabl

object @customer => :profile
attributes :id, :username, :customer_id, :first_name, :last_name, :avatar_url

The output when hitting 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
            }
        }
    ]
}

The problem is that I hope the "target" nodes within the "targets" array to be named "profile". Like this:

{
        "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
                }
            }
        ]
    }

Note the "profile" nodes instead of the "target" nodes.

How do I achieve this?

2

2 Answers

2
votes

I think this should work too. Enter this in targets/index.json.rabl:

collection @customers => :targets

child :profile do
  extends 'customers/profile'
end

And in customers/profile.json.rabl:

object @profile
attributes :id, :username, :customer_id, :first_name, :last_name, :avatar_url
0
votes

Something like this should work... Currently not using RABL anymore, but this is how I remember it...

node :profile do 
  attributes :id, :username, :customer_id, :first_name, :last_name, :avatar_url
end