This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/lib/tasks/items.rake

19 lines
377 B
Ruby
Raw Normal View History

2012-05-11 08:16:09 +00:00
# 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