better examples in ActiveModel readme
This commit is contained in:
parent
b83e0c3f29
commit
2d2c82354f
|
@ -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}"
|
||||
|
|
Loading…
Reference in New Issue