better examples in ActiveModel readme

This commit is contained in:
Hrvoje Šimić 2012-10-19 16:58:30 +02:00
parent b83e0c3f29
commit 2d2c82354f
1 changed files with 15 additions and 1 deletions

View File

@ -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}"