【发布时间】:2014-06-18 16:18:39
【问题描述】:
我正在使用 rails 中的祖先 gem 来嵌套一些 cmets,我想要的是让您能够获取所有 cmets,然后将它们全部嵌套。当我将:@comments = post.comments.arrange_serializable 放入我的 cmets 控制器索引操作并获得以下结果时,我如何得到以下结果:
{
"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":[
]
}
]
}
很明显,id: 5 的评论应该在 children 的数组中,它位于评论 id: 4 中,IS 嵌套在 id: 3 的评论下。
有人能告诉我为什么arrange_serializable 没有“多巢”cmets 吗?或者如果有其他功能可以做到这一点。
【问题讨论】:
标签: ruby-on-rails ruby ancestry