简体   繁体   English

Rails 4.2.2-如何使用祖先宝石?

[英]Rails 4.2.2 - How to use ancestry gem?

In rails 4.2.2, I am using jstree and ancestry gems for folder and files structure. 在Rails 4.2.2中,我将jstreeancestry gem用于文件夹和文件结构。 How can I use ancestry methods in our model? 如何在模型中使用祖先方法? Please give some examples with full model structure. 请提供一些具有完整模型结构的示例。 I have already tried it by referring this https://github.com/stefankroes/ancestry , but I don't know whether generated result is correct or not. 我已经通过参考https://github.com/stefankroes/ancestry尝试过,但是我不知道生成的结果是否正确。

Please help me to create ancestry model structure and how can I use it for jstree. 请帮助我创建祖先模型结构,以及如何将其用于jstree。

if you haven't used it before, I'd suggest just building a tree in rails console like have a Header class that has name (and obviously ancestry ) and do (off the top of my head): 如果您以前从未使用过它,我建议您仅在Rails控制台中构建一棵树,例如具有具有name (显然是ancestry )的Header类并做(不在我的头上):

class Header < ActiveRecord::Base
  has_ancestry
end

> h1=Header.create name:"h1"
> h2=Header.create name:"h2", parent: h1
> h1.reload
> h1.children
> h3=Header.create name:"h2", parent: h2
> h1.reload
> h1.children

That will start you with the basics of how the gem works 这将使您开始了解宝石的工作原理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM