Permalink
Browse files

better examples in ActiveModel readme

  • Loading branch information...
1 parent b83e0c3 commit 2d2c82354fbde7769b898d476c4d161130504391 @shime shime committed Oct 19, 2012
Showing with 15 additions and 1 deletion.
  1. +15 −1 activemodel/README.rdoc
View
@@ -75,7 +75,11 @@ behavior out of the box:
* Tracking value changes
- The ActiveModel::Dirty module allows for tracking attribute changes:
+ class Person
+ include ActiveModel::Dirty
+
+ attr_accessor :name
+ end
person = Person.new
person.name # => nil
@@ -152,6 +156,16 @@ behavior out of the box:
ActiveModel::Serialization provides a standard interface for your object
to provide +to_json+ or +to_xml+ serialization.
+ class SerialPerson
+ include ActiveModel::Serialization
+
+ attr_accessor :name
+
+ def attributes
+ {'name' => name}
+ end
+ end
+
s = SerialPerson.new
s.serializable_hash # => {"name"=>nil}
s.to_json # => "{\"name\":null}"

0 comments on commit 2d2c823

Please sign in to comment.