如何使用awesome_nested_set重新排序节点内的节点

时间:2010-04-14 19:53:28

标签: ruby-on-rails nested-sets acts-as-nested-set

如果我有这样的树:

Page1
---Page1.1
---Page1.2
---Page1.3

使用awesome_nested_set,如何在Page1节点内向上或向下移动Page1.x?

感谢。

1 个答案:

答案 0 :(得分:9)

来自http://github.com/collectiveidea/awesome_nested_set/blob/master/lib/awesome_nested_set.rb

# Shorthand method for finding the left sibling and moving to the left of it.
def move_left
  move_to_left_of left_sibling
end

#Shorthand method for finding the right sibling and moving to the right of it.
def move_right
  move_to_right_of right_sibling
end

# Move the node to the left of another node (you can pass id only)
def move_to_left_of(node)
  move_to node, :left
end

# Move the node to the left of another node (you can pass id only)
def move_to_right_of(node)
  move_to node, :right
end