Add mongoid-tree to Item
This commit is contained in:
1 parent
fd52d00187
commit
6a443f0976
13 files changed
+60
-95
No files matched your search
@@ -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
|
||||
Reference in new issue
Block a user