Permalink
Browse files

Fixed readme for ActiveModel::Dirty

  • Loading branch information...
1 parent d1bedd1 commit db274a02edf0b7057342de308b42ecf7f9ca4181 @mikel mikel committed Jan 16, 2010
Showing with 22 additions and 4 deletions.
  1. +22 −4 activemodel/README
View
@@ -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']}
-
+
+ {Learn more}[link:classes/ActiveModel/Dirty.html]

0 comments on commit db274a0

Please sign in to comment.