Skip to content

Instantly share code, notes, and snippets.

@JuanitoFatas
Created December 1, 2013 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JuanitoFatas/7734979 to your computer and use it in GitHub Desktop.
Save JuanitoFatas/7734979 to your computer and use it in GitHub Desktop.
Active Support Callbacks
require 'active_support'
class Record
include ActiveSupport::Callbacks
define_callbacks :save
def save
run_callbacks :save do
puts "save!"
end
end
end
class PersonRecord < Record
set_callback :save, :before, :before_save_message
set_callback :save, :after, :after_save_message
def before_save_message
puts "before save"
end
def after_save_message
puts "after save"
end
end
person = PersonRecord.new
person.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment