Skip to content

Commit b34d532

Browse files
committed
Merge pull request #1462 from nate00/attribute-overriding--update-docs
Update attribute/association overriding docs
2 parents 8981683 + 0a937a0 commit b34d532

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

docs/general/serializers.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,31 +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-
attributes :id, :body
192-
193-
has_many :comments
194-
195-
def comments
191+
has_many :comments do
196192
object.comments.active
197193
end
198194
end
199195
```
200196

201197
## Overriding attribute methods
202198

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

205201
```ruby
206202
class PostSerializer < ActiveModel::Serializer
207-
attributes :id, :body
208-
209-
has_many :comments
210-
211-
def body
203+
attribute :body do
212204
object.body.downcase
213205
end
214206
end

0 commit comments

Comments
 (0)