Skip to content

Commit da55cd1

Browse files
addressing comments / concerns
1 parent e9f2596 commit da55cd1

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This is the documentation of ActiveModelSerializers, it's focused on the **0.10.
1616
- [Instrumentation](general/instrumentation.md)
1717
- [JSON API Schema](jsonapi/schema.md)
1818
- [ARCHITECTURE](ARCHITECTURE.md)
19+
- [Passing Arbitrary Options](general/passing_arbitrary_options.md)
1920

2021
## How to
2122

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
## Passing Arbitrary Options To A Serializer
1+
[Back to Guides](../README.md)
2+
3+
# Passing Arbitrary Options To A Serializer
24

35
Let's say you have a basic Post Controller:
46

@@ -18,28 +20,26 @@ class PostSerializer < ActiveModel::Serializer
1820
end
1921
```
2022

21-
This works all fine and well, but maybe you passing in some "arbitrary" options
22-
into the serializer. Here's what you would do:
23+
This works all fine and well, but maybe you passing in some arbitrary options
24+
into the serializer. These options can be anything that isn't already reserved for use by
25+
ActiveModelSerializers' adapter options.
2326

24-
### posts_controller.rb
27+
Here's an example:
2528

2629
```ruby
27-
...
30+
# posts_controller.rb
31+
class PostController < ApplicationController
2832
def dashboard
2933
render json: @posts, user_id: 12
3034
end
31-
...
32-
```
35+
end
3336

34-
### posts_serializer.rb
37+
# post_serializer.rb
38+
class PostSerializer < ActiveModel::Serializer
39+
attributes :id, :title, :body
3540

36-
```ruby
37-
...
3841
def comments_by_me
3942
Comments.where(user_id: instance_options[:user_id], post_id: object.id)
4043
end
41-
...
44+
end
4245
```
43-
44-
These options can be anything that isn't already reserved for use by
45-
ActiveModelSerializers' adapter options.

0 commit comments

Comments
 (0)