aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/observer.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-03-02 03:02:51 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-03-02 03:02:51 +0000
commita4c6442612b50574795a52add5b9405f7028aab3 (patch)
tree1e82a079284b8eaa8b35f105275021dfba7ff772 /activerecord/lib/active_record/observer.rb
parent7864d0e0120f8c7b592056ecce171c369cb1e94b (diff)
downloadrails-a4c6442612b50574795a52add5b9405f7028aab3.tar.gz
rails-a4c6442612b50574795a52add5b9405f7028aab3.tar.bz2
rails-a4c6442612b50574795a52add5b9405f7028aab3.zip
More docs for observers (closes #3996) [Robby Russel]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3744 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/observer.rb')
-rw-r--r--activerecord/lib/active_record/observer.rb22
1 files changed, 21 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/observer.rb b/activerecord/lib/active_record/observer.rb
index 51829c6651..97aa58872a 100644
--- a/activerecord/lib/active_record/observer.rb
+++ b/activerecord/lib/active_record/observer.rb
@@ -42,6 +42,18 @@ module ActiveRecord
#
# This Observer sends an email when a Comment#save is finished.
#
+ # class ContactObserver < ActiveRecord::Observer
+ # def after_create(contact)
+ # contact.logger.info('New contact added!')
+ # end
+ #
+ # def after_destroy(contact)
+ # contact.logger.warn("Contact with an id of #{contact.id} was destroyed!")
+ # end
+ # end
+ #
+ # This Observer uses logger to log when specific callbacks are triggered.
+ #
# == Observing a class that can't be inferred
#
# Observers will by default be mapped to the class with which they share a name. So CommentObserver will
@@ -72,12 +84,20 @@ module ActiveRecord
#
# The observer can implement callback methods for each of the methods described in the Callbacks module.
#
- # == Triggering Observers
+ # == Storing Observers in Rails
+ #
+ # If you're using Active Record within Rails, observer classes are usually stored in app/models with the
+ # naming convention of app/models/audit_observer.rb.
+ #
+ # == Configuration
#
# In order to activate an observer, list it in the <tt>config.active_record.observers</tt> configuration setting in your
# <tt>config/environment.rb</tt> file.
#
# config.active_record.observers = :comment_observer, :signup_observer
+ #
+ # Observers will not be invoked unless you define these in your application configuration.
+ #
class Observer
include Singleton