#133 making :serializer and :polymorphic documentation less verbose

This commit is contained in:
Gary S. Weaver 2012-10-09 09:37:59 -04:00
parent 257adfc80e
commit 9cd472c160

View File

@ -328,35 +328,11 @@ class PostSerializer < ActiveModel::Serializer
end end
``` ```
Use the `:serializer` option to specify a custom serializer class: You may also use the `:serializer` option to specify a custom serializer class and the `:polymorphic` option to specify an association that is polymorphic (STI), e.g.:
```ruby ```ruby
class PostSerializer < ActiveModel::Serializer
attributes :id, :title, :body
has_one :author
has_many :comments, :serializer => CommentShortSerializer has_many :comments, :serializer => CommentShortSerializer
def include_associations!
include! :author if scope.admin?
include! :comments unless object.comments_disabled?
end
end
```
Use the `:polymorphic` option to specify an association that is polymorphic (STI):
```ruby
class PostSerializer < ActiveModel::Serializer
attributes :id, :title, :body
has_one :author
has_many :comments
has_one :reviewer, :polymorphic => true has_one :reviewer, :polymorphic => true
def include_associations!
include! :author if scope.admin?
include! :comments unless object.comments_disabled?
end
end
``` ```
## Embedding Associations ## Embedding Associations