aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source
diff options
context:
space:
mode:
authorVishnu Atrai <vishnu.atrai@gmail.com>2011-08-05 13:13:22 +0530
committerXavier Noria <fxn@hashref.com>2011-08-13 16:22:30 -0700
commit4bde1b0041d73accf75525697461ac6b9fad5404 (patch)
tree65acf2d0f5c81961d7b66ab16e455ade266128b7 /railties/guides/source
parentac287b2aa04c8376bf7d1f95c99047796442406e (diff)
downloadrails-4bde1b0041d73accf75525697461ac6b9fad5404.tar.gz
rails-4bde1b0041d73accf75525697461ac6b9fad5404.tar.bz2
rails-4bde1b0041d73accf75525697461ac6b9fad5404.zip
ActiveModel::AttributeMethods basic guide
Diffstat (limited to 'railties/guides/source')
-rw-r--r--railties/guides/source/active_model_basics.textile27
1 files changed, 26 insertions, 1 deletions
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index 5e41d39447..c76469f62c 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -8,8 +8,33 @@ WARNING. This Guide is based on Rails 3.0. Some of the code shown here will not
h3. Introduction
-Active Model is a library containing various modules used in developing frameworks that need to interact with the Rails Action Pack library. Active Model provides a known set of interfaces for usage in classes.
+Active Model is a library containing various modules used in developing frameworks that need to interact with the Rails Action Pack library. Active Model provides a known set of interfaces for usage in classes. Some of modules are explained below -
+h4. AttributeMethods
+
+AttributeMethods module can add custom prefixes and suffixes on methods of a class. It is used by defining the prefixes and suffixes, which methods on the object will use them.
+
+<ruby>
+class Person
+ include ActiveModel::AttributeMethods
+
+ attribute_method_prefix 'reset_'
+ attribute_method_suffix '_highest?'
+ define_attribute_methods ['age']
+
+ attr_accessor :age
+
+private
+ def reset_attribute(attribute)
+ send("#{attribute}=", 0)
+ end
+
+ def attribute_highest?(attribute)
+ attribute > 100 ? true : false
+ end
+
+end
+</ruby>
h3. Changelog