aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVishnu Atrai <vishnu.atrai@gmail.com>2011-08-05 14:35:04 +0530
committerXavier Noria <fxn@hashref.com>2011-08-13 16:22:31 -0700
commit33d7a6bc55a983ea690961d3a434096fe80d0fca (patch)
treec1fb0fe7174082a09cf21cb2031cc6ba46f851f6
parentbc49d6d1eb075900657b0f94d03c51d18a95a54d (diff)
downloadrails-33d7a6bc55a983ea690961d3a434096fe80d0fca.tar.gz
rails-33d7a6bc55a983ea690961d3a434096fe80d0fca.tar.bz2
rails-33d7a6bc55a983ea690961d3a434096fe80d0fca.zip
ActiveModel::Callbacks basic guide
-rw-r--r--railties/guides/source/active_model_basics.textile24
1 files changed, 24 insertions, 0 deletions
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index 87a9658a94..e4c84365d3 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -45,7 +45,31 @@ person.age_highest? # false
h4. Callbacks
+Callbacks gives Active Record style callbacks. This provides the ability to define the callbacks and those will run at appropriate time. After defining a callbacks you can wrap with before, after and around custom methods.
+<ruby>
+class Person
+ extend ActiveModel::Callbacks
+
+ define_model_callbacks :update
+
+ before_update :reset_me
+
+ def update
+ _run_update_callbacks do
+ puts 'saving...'
+ end
+ end
+
+ def reset_me
+ puts 'before saving...'
+ end
+end
+
+person = Person.new
+person.update # before saving...
+ # saving...
+</ruby>
h3. Changelog