From a4c6442612b50574795a52add5b9405f7028aab3 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 2 Mar 2006 03:02:51 +0000 Subject: More docs for observers (closes #3996) [Robby Russel] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3744 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/observer.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'activerecord') 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 config.active_record.observers configuration setting in your # config/environment.rb 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 -- cgit v1.2.3