Ruby on rails RABL更改根节点名称
rabl在更改嵌套节点名称时遇到问题: 例如,下面是我的targets/index.json.rablRuby on rails RABL更改根节点名称,ruby-on-rails,ruby,rabl,Ruby On Rails,Ruby,Rabl,rabl在更改嵌套节点名称时遇到问题: 例如,下面是我的targets/index.json.rabl collection @customers => :targets extends 'customers/profile' object @customer => :profile attributes :id, :username, :customer_id, :first_name, :last_name, :avatar_url 这是我的客户/profile.json.r
collection @customers => :targets
extends 'customers/profile'
object @customer => :profile
attributes :id, :username, :customer_id, :first_name, :last_name, :avatar_url
这是我的客户/profile.json.rabl
collection @customers => :targets
extends 'customers/profile'
object @customer => :profile
attributes :id, :username, :customer_id, :first_name, :last_name, :avatar_url
命中targets.json(targets#index)时的输出:
问题是,我希望将“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
}
}
]
}
注意“profile”节点,而不是“target”节点
我怎样才能做到这一点呢?像这样的事情应该会奏效。。。目前不再使用RABL,但这就是我对它的记忆
node :profile do
attributes :id, :username, :customer_id, :first_name, :last_name, :avatar_url
end
我认为这也应该奏效。在targets/index.json.rabl中输入以下内容:
collection @customers => :targets
child :profile do
extends 'customers/profile'
end
object @profile
attributes :id, :username, :customer_id, :first_name, :last_name, :avatar_url
在customers/profile.json.rabl中:
collection @customers => :targets
child :profile do
extends 'customers/profile'
end
object @profile
attributes :id, :username, :customer_id, :first_name, :last_name, :avatar_url
这很容易,我换了工作:p如果我需要的话,我以后还会用它。