diff options
author | Hrvoje Šimić <shime.ferovac@gmail.com> | 2012-10-19 16:58:30 +0200 |
---|---|---|
committer | Hrvoje Šimić <shime.ferovac@gmail.com> | 2012-10-19 16:58:30 +0200 |
commit | 2d2c82354fbde7769b898d476c4d161130504391 (patch) | |
tree | ce2000319bdb562c352a1ef0e14041dd29486285 /activemodel | |
parent | b83e0c3f293b9c68037f55e2ffe3b134ac98a91d (diff) | |
download | rails-2d2c82354fbde7769b898d476c4d161130504391.tar.gz rails-2d2c82354fbde7769b898d476c4d161130504391.tar.bz2 rails-2d2c82354fbde7769b898d476c4d161130504391.zip |
better examples in ActiveModel readme
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/README.rdoc | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/activemodel/README.rdoc b/activemodel/README.rdoc index fc34d69ff6..4adb43a015 100644 --- a/activemodel/README.rdoc +++ b/activemodel/README.rdoc @@ -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}" |