mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Use new block-based attribute override in docs
This commit is contained in:
parent
da85d944d4
commit
0a937a0fba
@ -184,13 +184,11 @@ For more information, see [the Serializer class on GitHub](https://github.com/ra
|
||||
|
||||
## 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
|
||||
class PostSerializer < ActiveModel::Serializer
|
||||
has_many :comments
|
||||
|
||||
def comments
|
||||
has_many :comments do
|
||||
object.comments.active
|
||||
end
|
||||
end
|
||||
@ -198,13 +196,11 @@ end
|
||||
|
||||
## Overriding attribute methods
|
||||
|
||||
If you want to override any attribute, you can use:
|
||||
To override an attribute, call `attribute` with a block:
|
||||
|
||||
```ruby
|
||||
class PostSerializer < ActiveModel::Serializer
|
||||
attributes :body
|
||||
|
||||
def body
|
||||
attribute :body do
|
||||
object.body.downcase
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user