aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/README
diff options
context:
space:
mode:
authorMikel Lindsaar <raasdnil@gmail.com>2010-01-16 22:21:07 +1100
committerMikel Lindsaar <raasdnil@gmail.com>2010-01-16 22:21:07 +1100
commitdb274a02edf0b7057342de308b42ecf7f9ca4181 (patch)
tree1a7815fb89d6c15fea8a03b450ad9d3e2df33a4e /activemodel/README
parentd1bedd182bbaae68424c96d24fe5b970ef12779b (diff)
downloadrails-db274a02edf0b7057342de308b42ecf7f9ca4181.tar.gz
rails-db274a02edf0b7057342de308b42ecf7f9ca4181.tar.bz2
rails-db274a02edf0b7057342de308b42ecf7f9ca4181.zip
Fixed readme for ActiveModel::Dirty
Diffstat (limited to 'activemodel/README')
-rw-r--r--activemodel/README26
1 files changed, 22 insertions, 4 deletions
diff --git a/activemodel/README b/activemodel/README
index 46f02aa651..0c558ed85a 100644
--- a/activemodel/README
+++ b/activemodel/README
@@ -41,20 +41,38 @@ You can include functionality from the following modules:
* Tracking changes in your object
- class MyClass
+ class Person
include ActiveModel::Dirty
+
+ define_attribute_methods [:name]
+
+ def name
+ @name
+ end
+
+ def name=(val)
+ name_will_change!
+ @name = val
+ end
+
+ def save
+ @previously_changed = changes
+ true
+ end
end
...provides all the value tracking features implemented by ActiveRecord
- person.name # => 'bill'
+ person = Person.new
+ person.name # => nil
person.changed? # => false
person.name = 'bob'
person.changed? # => true
person.changed # => ['name']
- person.changes # => { 'name' => ['bill', 'bob'] }
+ person.changes # => { 'name' => [nil, 'bob'] }
person.name = 'robert'
person.save
person.previous_changes # => {'name' => ['bob, 'robert']}
- \ No newline at end of file
+
+ {Learn more}[link:classes/ActiveModel/Dirty.html]