Use new block-based attribute override in docs

This commit is contained in:
Nate Sullivan 2016-01-23 18:51:48 -08:00
parent da85d944d4
commit 0a937a0fba

View File

@ -184,13 +184,11 @@ For more information, see [the Serializer class on GitHub](https://github.com/ra
## Overriding association methods ## Overriding association methods
If you want to override any association, you can use: To override an association, call `has_many`, `has_one` or `belongs_to` with a block:
```ruby ```ruby
class PostSerializer < ActiveModel::Serializer class PostSerializer < ActiveModel::Serializer
has_many :comments has_many :comments do
def comments
object.comments.active object.comments.active
end end
end end
@ -198,13 +196,11 @@ end
## Overriding attribute methods ## Overriding attribute methods
If you want to override any attribute, you can use: To override an attribute, call `attribute` with a block:
```ruby ```ruby
class PostSerializer < ActiveModel::Serializer class PostSerializer < ActiveModel::Serializer
attributes :body attribute :body do
def body
object.body.downcase object.body.downcase
end end
end end