method

before_destroy

before_destroy()
public

Is called before Base.destroy.

Note: If you need to destroy or nullify associated records first, use the :dependent option on your associations.

2Notes

Where you declare before_destroy matters

chrisrbailey · Jul 16, 20088 thanks

Beware that where you declare a before_destroy callback matters if you have any "acts_as" type declarations, that also declare before_destroy callbacks. A good example is the acts_as_nested_set. If you specify acts_as_nested_set prior to your before_destroy, then acts_as_nested_set will go through and destroy all children first, then your callback will run (at which point children will be empty). Thus, if your before_destroy callback needs to examine the children, it will not work properly. Putting your before_destroy callback ahead of acts_as_nested_set or anything else that declares a before_destroy is key in such cases.

See ActiveRecord:Callbacks for details about how before_* and after_* are handled

kevmoo · Oct 27, 20091 thank

ActiveRecord::Callbacks