5. Validations
• Most Rails validations originate from ActiveModel
• Including ActiveModel::Validations gives you
• #valid?
• #errors
• Class methods for validation API
9. Callbacks
• In ActiveRecord, this is how before_create,
after_create and around_create are made.
• Two different steps: register callbacks and
execute callbacks.
10. Observers
• Use observers to decouple logic from
models.
• Observers use convention to identify
targets: ModelObserver observes Model
unless explicitly overridden.
11. Serialization
• Allows for models to define how they
would like to be serialized in a variety of
formats (including XML and JSON).
• Important for creation of presenters that
get sent as JSON in RESTful API.
12. Dirty
• ActiveModel provides an API for detecting
whether an object is “dirty” or not
(changed).
• Could be useful for operations that may or
may not be idempotent and you need to
know which (e.g. marking a message as
read).