| Module | ActsAsFileSystem::ClassMethods |
| In: |
lib/acts_as_filesystem.rb
|
Declares the ActiveRecord model to acts like a filesystem: objects are arranged in a tree (liks acts_as_tree), and . The underlying table must have the following fields:
# File lib/acts_as_filesystem.rb, line 16
16: def acts_as_filesystem
17:
18: include ActsAsFileSystem::InstanceMethods
19:
20: # a filesystem is a tree
21: acts_as_tree :order => 'name', :counter_cache => :children_count
22:
23: # calculate the right path
24: before_create do |record|
25: if record.path == record.slug && (! record.top_level?)
26: record.path = record.calculate_path
27: end
28: true
29: end
30:
31: # when renaming a category, all children categories must have their paths
32: # recalculated
33: after_update do |record|
34: if record.recalculate_path
35: record.children.each do |item|
36: item.path = item.calculate_path
37: item.recalculate_path = true
38: item.save!
39: end
40: end
41: record.recalculate_path = false
42: true
43: end
44:
45: end