- Defined in:
The instance_hooks plugin allows you to add hooks to specific instances, by passing a block to a _hook method (e.g. before_save_hookdo_something). The block is executed when the hook is called (e.g. before_save).
All of the standard hooks are supported. Instance level before hooks are executed in reverse order of addition before calling super. Instance level after hooks are executed in order of addition after calling super.
Instance level hooks for before and after are cleared after all related after level instance hooks have run. This means that if you add a before_create and before_update instance hooks to a new object, the before_create hook will be run the first time you save the object (creating it), and the before_update hook will be run the second time you save the object (updating it), and no hooks will be run the third time you save the object.
Validation hooks are not cleared until after a successful save.
# Add the instance hook methods to all model subclass instances (called before loading subclasses) ::. :instance_hooks # Add the instance hook methods just to Album instances Album.plugin :instance_hooks
Defined Under Namespace