aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model
diff options
context:
space:
mode:
authorrusikf <rs41@gmx.com>2015-05-04 11:34:52 +0300
committerRuslan Korolev <rs41@gmx.com>2015-05-11 13:10:30 +0300
commit47896b3d08242e641b2bc2c2b8920d4b8e4e7804 (patch)
tree4bcce71ebf239ea63f37fd0e299738aeb18dc439 /activemodel/lib/active_model
parent4261aa575a6f5f12486a19fe11464e614314e296 (diff)
downloadrails-47896b3d08242e641b2bc2c2b8920d4b8e4e7804.tar.gz
rails-47896b3d08242e641b2bc2c2b8920d4b8e4e7804.tar.bz2
rails-47896b3d08242e641b2bc2c2b8920d4b8e4e7804.zip
add docs to include option at ActiveModel::Serialization#serializable_hash [ci skip]
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r--activemodel/lib/active_model/serialization.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/serialization.rb b/activemodel/lib/active_model/serialization.rb
index c06a64c75f..c82c4b67f5 100644
--- a/activemodel/lib/active_model/serialization.rb
+++ b/activemodel/lib/active_model/serialization.rb
@@ -94,6 +94,37 @@ module ActiveModel
# person.serializable_hash(except: :name) # => {"age"=>22}
# person.serializable_hash(methods: :capitalized_name)
# # => {"name"=>"bob", "age"=>22, "capitalized_name"=>"Bob"}
+ #
+ # Example with <tt>:include</tt> option
+ #
+ # class User
+ # include ActiveModel::Serializers::JSON
+ # attr_accessor :name, :notes # Emulate has_many :notes
+ # def attributes
+ # {'name' => nil}
+ # end
+ # end
+ #
+ # class Note
+ # include ActiveModel::Serializers::JSON
+ # attr_accessor :title, :text
+ # def attributes
+ # {'title' => nil, 'text' => nil}
+ # end
+ # end
+ #
+ # note = Note.new
+ # note.title = 'Battle of Austerlitz'
+ # note.text = 'Some text here'
+ #
+ # user = User.new
+ # user.name = 'Napoleon'
+ # user.notes = [note]
+ #
+ # user.serializable_hash
+ # #=> {"name" => "Napoleon"}
+ # user.serializable_hash(include: { notes: { only: 'title' }})
+ # #=> {"name" => "Napoleon", "notes" => [{"title"=>"Battle of Austerlitz"}]}
def serializable_hash(options = nil)
options ||= {}