我正在使用 rails 中的祖先 gem 来嵌套一些评论,而我想要的是让您能够获得所有评论,然后将它们全部嵌套。当我将:@comments = post.comments.arrange_serializable
放入我的评论控制器索引操作并获得以下结果时,我如何得到以下结果:
{
"comments":[
{
"id":3,
"comment":"284723nbrkdgfiy2r84ygwbdjhfg8426trgfewuhjf",
"author":"asdasdasdas",
"post_id":268,
"ancestry":null,
"created_at":"2014-06-17T19:23:04.667Z",
"updated_at":"2014-06-17T19:23:04.667Z",
"children":[
{
"id":4,
"comment":"284723nbrkdgfiy2r84ygwbdjhfg8426trgfewuhjf",
"author":"asdasdasdas",
"post_id":268,
"ancestry":"3",
"created_at":"2014-06-17T19:24:02.408Z",
"updated_at":"2014-06-17T19:24:02.408Z",
"children":[
]
}
]
},
{
"id":5,
"comment":"97ryhewfkhbdasifyt834rygewbfj,dhsg834",
"author":"asdasdasd",
"post_id":268,
"ancestry":"4",
"created_at":"2014-06-17T20:30:04.887Z",
"updated_at":"2014-06-17T20:38:16.060Z",
"children":[
]
}
]
}
很明显,comment with应该位于位于comment with下嵌套的 commentid: 5
的数组中。children
id: 4
id: 3
有人能告诉我为什么arrange_serializable
没有“多巢”评论吗?或者如果有另一个功能可以做到这一点。