Skip to content

Commit

Permalink
better examples in ActiveModel readme
Browse files Browse the repository at this point in the history
  • Loading branch information
shime committed Oct 19, 2012
1 parent b83e0c3 commit 2d2c823
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion activemodel/README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down

0 comments on commit 2d2c823

Please sign in to comment.