Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Callbacks gives any class Active Record–style callbacks. It is used by defining the callbacks that the model will use, then in your model running the callbacks at the appropriate time. Once defined you have access to before, after, and around custom methods.
class Record
extend ActiveModel::Callbacks
define_model_callbacks :create
define_model_callbacks :update, :destroy, :only => :before
before_update :my_callback
def save
_run_update_callbacks do
# Your save code here
end
end
private
def my_callback
# Your callback code here
end
end