In your rabl file try this:
child @users, object_root: false do
attributes :id, :name
end
node(:total) { @users.size }
質問
I recently came across a condition were i wanted to send two objects in the RABL as a response.
[
{
id: "1",
name: "XYZ"
},
{
id: "1",
name: "XYZ"
},
{
total: "2"
}
]
All I could manage was this , which is not correct.
[
{
id: "1",
name: "XYZ",
total: "2"
},
{
id: "1",
name: "XYZ",
total: "2"
}
]
I Found a solution which was to use a partial to iterate on the object and just add a new
node(:name) {partial("users/names", :object => @users)}
node(:total){ @total}
This is a hack, which i don't want because it wraps all the names in a node . Is there any other way to do it ?
解決
In your rabl file try this:
child @users, object_root: false do
attributes :id, :name
end
node(:total) { @users.size }