Skip to content

Commit 0a937a0

Browse files
committed
Use new block-based attribute override in docs
1 parent da85d94 commit 0a937a0

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

docs/general/serializers.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,27 +184,23 @@ For more information, see [the Serializer class on GitHub](https://github.com/ra
184184

185185
## Overriding association methods
186186

187-
If you want to override any association, you can use:
187+
To override an association, call `has_many`, `has_one` or `belongs_to` with a block:
188188

189189
```ruby
190190
class PostSerializer < ActiveModel::Serializer
191-
has_many :comments
192-
193-
def comments
191+
has_many :comments do
194192
object.comments.active
195193
end
196194
end
197195
```
198196

199197
## Overriding attribute methods
200198

201-
If you want to override any attribute, you can use:
199+
To override an attribute, call `attribute` with a block:
202200

203201
```ruby
204202
class PostSerializer < ActiveModel::Serializer
205-
attributes :body
206-
207-
def body
203+
attribute :body do
208204
object.body.downcase
209205
end
210206
end

0 commit comments

Comments
 (0)