我正在使用mongoid_nested_set,如何简化这段代码:
category.ancestors.where(depth: 3).first以前我用过:
category.ancestors[3]但这在mongoid 3.1.5 / rails 3.2.13 / ruby 1.9.3 / acticeadmin-mongoid 0.3.0中似乎不起作用。
发布于 2013-11-27 12:19:25
最后,罪魁祸首是acticeadmin_mongoid 0.3.0,我删除了它,一切都很好。
发布于 2013-11-21 12:13:06
你用的是祖先宝石吗?
如果需要,则可以在本例中使用它们的命名范围。
category.ancestors.to_depth(3) # Return nodes up to depth 3 (1 and 2 also included)
category.ancestors.at_depth(depth) # Return nodes with the exact depth of 3正如在自述文件中所看到的。
https://stackoverflow.com/questions/20120577
复制相似问题