aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/README
diff options
context:
space:
mode:
authorMikel Lindsaar <raasdnil@gmail.com>2010-01-17 12:42:53 +1100
committerMikel Lindsaar <raasdnil@gmail.com>2010-01-17 12:42:53 +1100
commit8834b2612b7ddda70ee6a685eb0063d3daa8e63d (patch)
tree5686b261c8f258e8e227e6b58cdab689c23341e8 /activemodel/README
parente1c15d9fa147fd067b619ab4ad369fe0f80f1840 (diff)
downloadrails-8834b2612b7ddda70ee6a685eb0063d3daa8e63d.tar.gz
rails-8834b2612b7ddda70ee6a685eb0063d3daa8e63d.tar.bz2
rails-8834b2612b7ddda70ee6a685eb0063d3daa8e63d.zip
Adding ActiveModel::AttributeMethods documentation
Diffstat (limited to 'activemodel/README')
-rw-r--r--activemodel/README25
1 files changed, 23 insertions, 2 deletions
diff --git a/activemodel/README b/activemodel/README
index cc687e51ed..c8814a9ea3 100644
--- a/activemodel/README
+++ b/activemodel/README
@@ -12,9 +12,30 @@ 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 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 MyClass
+ class Person
extend ActiveModel::Callbacks
define_model_callbacks :create
@@ -32,7 +53,7 @@ functionality from the following modules:
* For classes that already look like an Active Record object
- class MyClass
+ class Person
include ActiveModel::Conversion
end