Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add documentation of the callbacks

  • Loading branch information...
commit c6ecebca4411a77bff417b131aa0c3c5648aee5e 1 parent a5f7d9c
@tmaier tmaier authored parndt committed
Showing with 51 additions and 0 deletions.
  1. +51 −0 README.rdoc
View
51 README.rdoc
@@ -43,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:
Please sign in to comment.
Something went wrong with that request. Please try again.