diff options
author | Radan Skoric <radan.skoric@gmail.com> | 2015-04-22 22:55:48 +0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-06-09 17:41:14 -0300 |
commit | 3d949f34816d6eca0a6b59cfa08d91f36e8e64dd (patch) | |
tree | 13be98737822ad0f75689c185a1893053b932d53 /activemodel/lib/active_model | |
parent | 1a82e20f084803d12480507c7ef00001a16b2916 (diff) | |
download | rails-3d949f34816d6eca0a6b59cfa08d91f36e8e64dd.tar.gz rails-3d949f34816d6eca0a6b59cfa08d91f36e8e64dd.tar.bz2 rails-3d949f34816d6eca0a6b59cfa08d91f36e8e64dd.zip |
Add code example for include option of AM::Serialization#serializable_hash
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/serialization.rb | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/serialization.rb b/activemodel/lib/active_model/serialization.rb index f95849eb84..144ee2ce6e 100644 --- a/activemodel/lib/active_model/serialization.rb +++ b/activemodel/lib/active_model/serialization.rb @@ -72,10 +72,20 @@ module ActiveModel module Serialization # Returns a serialized hash of your object. # + # class Address + # include ActiveModel::Serialization + # + # attr_accessor :city, :street + # + # def attributes + # {'city' => nil, 'street' => nil} + # end + # end + # # class Person # include ActiveModel::Serialization # - # attr_accessor :name, :age + # attr_accessor :name, :age, :address # # def attributes # {'name' => nil, 'age' => nil} @@ -89,6 +99,9 @@ module ActiveModel # person = Person.new # person.name = 'bob' # person.age = 22 + # person.address = Address.new + # person.address.city = 'New York' + # person.address.street = 'Main St' # person.serializable_hash # => {"name"=>"bob", "age"=>22} # person.serializable_hash(only: :name) # => {"name"=>"bob"} # person.serializable_hash(except: :name) # => {"age"=>22} |