Tag: 血统

Rails和Mutli嵌套中的祖先gem

我在rails中使用ancestry 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”:[ ] } ] } 非常明显的是, id: 5注释假设位于注释id: 4中的子数组中,这些注释id: 4嵌套在id: 3注释下。 有人可以告诉我为什么arrange_serializable不会“多巢”评论? 或者如果有另一个function来执行此操作。