Add mongoid-tree to Item

This commit is contained in:
Christophe Vilayphiou committed 2012-05-11 16:16:09 +08:00
1 parent fd52d00187
commit 6a443f0976
13 files changed
+60 -95

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
# encoding: utf-8
namespace :items do
task :tree_changes => :environment do
Item.all.each do |item|
item.position -= 1
item.parent_ids = ancestors(item)
item.rename(:full_name, :path)
item.save
end
end
def ancestors(item)
node, nodes = item, []
nodes << node = node.parent while !node.parent.blank? rescue nil
nodes.reverse
end
end