What is the Observer pattern in Rails and is it still used?

Answer

Rails once included ActiveRecord::Observer — a way to watch model lifecycle events from a separate class, reducing callback clutter in models. Example: class UserObserver < ActiveRecord::Observer; def after_create(user); Mailer.welcome(user).deliver; end; end. Observers were extracted to the rails-observers gem in Rails 4 and are no longer in Rails core. Modern alternatives: use callbacks sparingly in models (only for intrinsic model concerns), service objects for cross-cutting operations, event systems (Wisper, dry-events) for decoupled pub/sub, or ActiveSupport::Notifications for instrumenting and subscribing to app events.