谁为 awesome_nested_set 使用实例方法
who to use Instance methods for awesome_nested_set
我在 ROR 中实现了 awesome_nested_set gem,它有实例方法 (https://github.com/collectiveidea/awesome_nested_set/wiki/Awesome-nested-set-cheat-sheet)。我试过这个
Category.level(1)
但它显示错误
undefined method `level'
这也不起作用
@sa = Category.siblings('name'=>'new')
abort(@sa.siblings.inspect)
我如何实现这些
似乎 level
是实例,而不是 class 方法。
所以,
category = Category.create!(bla-bla-bla)
puts category.label # this shoud work
级别是实例方法
它在备忘单中说 here
实例方法
my_cat.root root for this node
my_cat.level the level of this object in the tree (e.g. root = 0)
my_cat.parent the node's immediate parent
my_cat.children array of immediate children (just those in the next level)
my_cat.ancestors array of all parents, parents' parents, etc, excluding self
my_cat.self_and_ancestors array of all parents, parents' parents, etc, including self
my_cat.siblings array of brothers and sisters (all at that level), excluding self
my_cat.self_and_siblings array of brothers and sisters (all at that level), including self
my_cat.descendants array of all children, children's children, etc., excluding self
my_cat.self_and_descendants array of all children, children's children, etc., including self
my_cat.leaves array of all descendants that have no children
所以在 Category
的实例中使用级别
为awesome_nested_set
使用实例方法
cat = Category.find_by_name("here")
subcats = cat.ancestors
abort(subcats.inspect)
我在 ROR 中实现了 awesome_nested_set gem,它有实例方法 (https://github.com/collectiveidea/awesome_nested_set/wiki/Awesome-nested-set-cheat-sheet)。我试过这个
Category.level(1)
但它显示错误
undefined method `level'
这也不起作用
@sa = Category.siblings('name'=>'new')
abort(@sa.siblings.inspect)
我如何实现这些
似乎 level
是实例,而不是 class 方法。
所以,
category = Category.create!(bla-bla-bla)
puts category.label # this shoud work
级别是实例方法
它在备忘单中说 here
实例方法
my_cat.root root for this node
my_cat.level the level of this object in the tree (e.g. root = 0)
my_cat.parent the node's immediate parent
my_cat.children array of immediate children (just those in the next level)
my_cat.ancestors array of all parents, parents' parents, etc, excluding self
my_cat.self_and_ancestors array of all parents, parents' parents, etc, including self
my_cat.siblings array of brothers and sisters (all at that level), excluding self
my_cat.self_and_siblings array of brothers and sisters (all at that level), including self
my_cat.descendants array of all children, children's children, etc., excluding self
my_cat.self_and_descendants array of all children, children's children, etc., including self
my_cat.leaves array of all descendants that have no children
所以在 Category
为awesome_nested_set
使用实例方法cat = Category.find_by_name("here")
subcats = cat.ancestors
abort(subcats.inspect)