Created
December 1, 2013 14:58
-
-
Save JuanitoFatas/7734979 to your computer and use it in GitHub Desktop.
Active Support Callbacks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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