diff options
Diffstat (limited to 'activemodel/README')
-rw-r--r-- | activemodel/README | 55 |
1 files changed, 39 insertions, 16 deletions
diff --git a/activemodel/README b/activemodel/README index 7c9c754a8e..c8814a9ea3 100644 --- a/activemodel/README +++ b/activemodel/README @@ -12,32 +12,55 @@ Active Model provides a known set of interfaces that your objects can implement to then present a common interface to the Action Pack helpers. You can include functionality from the following modules: -* Adding callbacks to your class - - class MyClass - extend ActiveModel::Callbacks - define_model_callbacks :create - - def create - _run_create_callbacks do - # Your create action methods here - end - end - end - - ...gives you before_create, around_create and after_create class methods that - wrap your create method. +* Adding attribute magic to your objects + + Add prefixes and suffixes to defined attribute methods... + + class Person + include ActiveModel::AttributeMethods + + attribute_method_prefix 'clear_' + define_attribute_methods [:name, :age] + + attr_accessor :name, :age + + def clear_attribute(attr) + send("#{attr}=", nil) + end + end + + ...gives you clear_name, clear_age. + + {Learn more}[link:classes/ActiveModel/AttributeMethods.html] + +* Adding callbacks to your objects + + class Person + extend ActiveModel::Callbacks + define_model_callbacks :create + + def create + _run_create_callbacks do + # Your create action methods here + end + end + end + + ...gives you before_create, around_create and after_create class methods that + wrap your create method. {Learn more}[link:classes/ActiveModel/CallBacks.html] * For classes that already look like an Active Record object - class MyClass + class Person include ActiveModel::Conversion end ...returns the class itself when sent :to_model + {Learn more}[link:classes/ActiveModel/Conversion.html] + * Tracking changes in your object Provides all the value tracking features implemented by ActiveRecord... |