diff options
Diffstat (limited to 'lib/plugins/awesome_nested_set/README.rdoc')
-rw-r--r-- | lib/plugins/awesome_nested_set/README.rdoc | 61 |
1 files changed, 57 insertions, 4 deletions
diff --git a/lib/plugins/awesome_nested_set/README.rdoc b/lib/plugins/awesome_nested_set/README.rdoc index 6a7380b60..2ba2128ec 100644 --- a/lib/plugins/awesome_nested_set/README.rdoc +++ b/lib/plugins/awesome_nested_set/README.rdoc @@ -16,7 +16,8 @@ This is a new implementation of nested set based off of BetterNestedSet that fix == Usage -To make use of awesome_nested_set, your model needs to have 3 fields: lft, rgt, and parent_id: +To make use of awesome_nested_set, your model needs to have 3 fields: lft, rgt, and parent_id. +You can also have an optional field: depth: class CreateCategories < ActiveRecord::Migration def self.up @@ -25,6 +26,7 @@ To make use of awesome_nested_set, your model needs to have 3 fields: lft, rgt, t.integer :parent_id t.integer :lft t.integer :rgt + t.integer :depth # this is optional. end end @@ -41,6 +43,57 @@ Enable the nested set functionality by declaring acts_as_nested_set on your mode Run `rake rdoc` to generate the API docs and see CollectiveIdea::Acts::NestedSet for more info. +== Callbacks + +There are three callbacks called when moving a node. `before_move`, `after_move` and `around_move`. + + class Category < ActiveRecord::Base + acts_as_nested_set + + after_move :rebuild_slug + around_move :da_fancy_things_around + + private + + def rebuild_slug + # do whatever + end + + def da_fancy_things_around + # do something... + yield # actually moves + # do something else... + end + end + +Beside this there are also hooks to act on the newly added or removed children. + + class Category < ActiveRecord::Base + acts_as_nested_set :before_add => :do_before_add_stuff, + :after_add => :do_after_add_stuff, + :before_remove => :do_before_remove_stuff, + :after_remove => :do_after_remove_stuff + + private + + def do_before_add_stuff(child_node) + # do whatever with the child + end + + def do_after_add_stuff(child_node) + # do whatever with the child + end + + def do_before_remove_stuff(child_node) + # do whatever with the child + end + + def do_after_remove_stuff(child_node) + # do whatever with the child + end + end + + == Protecting attributes from mass assignment It's generally best to "white list" the attributes that can be used in mass assignment: @@ -86,13 +139,13 @@ You can learn more about nested sets at: http://threebit.net/tutorials/nestedset If you find what you might think is a bug: 1. Check the GitHub issue tracker to see if anyone else has had the same issue. - http://github.com/collectiveidea/awesome_nested_set/issues/ + https://github.com/collectiveidea/awesome_nested_set/issues/ 2. If you don't see anything, create an issue with information on how to reproduce it. If you want to contribute an enhancement or a fix: -1. Fork the project on github. - http://github.com/collectiveidea/awesome_nested_set/ +1. Fork the project on GitHub. + https://github.com/collectiveidea/awesome_nested_set/ 2. Make your changes with tests. 3. Commit the changes without making changes to the Rakefile, VERSION, or any other files that aren't related to your enhancement or fix 4. Send a pull request. |