From 6da52c617e2a075b9d9e7142786f316d8f2c7930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 23 Nov 2011 23:22:46 +0000 Subject: Remove listings from the serialization guide that won't make 3.2. --- railties/guides/source/serializers.textile | 37 ------------------------------ 1 file changed, 37 deletions(-) (limited to 'railties/guides/source/serializers.textile') diff --git a/railties/guides/source/serializers.textile b/railties/guides/source/serializers.textile index 86a5e5ac8d..efc7cbf248 100644 --- a/railties/guides/source/serializers.textile +++ b/railties/guides/source/serializers.textile @@ -459,25 +459,6 @@ In other words, if a +PostSerializer+ is trying to serialize comments, it will f look for +PostSerializer::CommentSerializer+ before falling back to +CommentSerializer+ and finally +comment.as_json+. -h3. Optional Associations - -In some cases, you will want to allow a front-end to decide whether to include associated -content or not. You can achieve this easily by making an association *optional*. - - -class PostSerializer < ActiveModel::Serializer - attributes :title. :body - has_many :comments, :optional => true - - # ... -end - - -If an association is optional, it will not be included unless the request asks for it -with an +including+ parameter. The +including+ parameter is a comma-separated list of -optional associations to include. If the +including+ parameter includes an association -you did not specify in your serializer, it will receive a +401 Forbidden+ response. - h3. Overriding the Defaults h4. Authorization Scope @@ -500,24 +481,6 @@ which allows you to define a dynamic authorization scope based on the current re WARNING: If you use different objects as authorization scopes, make sure that they all implement whatever interface you use in your serializers to control what the outputted JSON looks like. -h4. Parameter to Specify Included Optional Associations - -In most cases, you should be able to use the default +including+ parameter to specify -which optional associations to include. If you are already using that parameter name or -want to reserve it for some reason, you can specify a different name by using the -+serialization_includes_param+ class method. - - -class PostsController < ApplicationController - serialization_includes_param :associations_to_include -end - - -You can also implement a +serialization_includes+ instance method, which should return an -Array of optional includes. - -WARNING: If you implement +serialization_includes+ and return an invalid association, your user will receive a +401 Forbidden+ exception. - h3. Using Serializers Outside of a Request The serialization API encapsulates the concern of generating a JSON representation of -- cgit v1.2.3