File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
Let's say you have a basic Post Controller:
4
4
5
- ```
5
+ ``` ruby
6
6
class PostController < ApplicationController
7
7
def dashboard
8
8
render json: @posts
12
12
13
13
Odds are, your serializer will look something like this:
14
14
15
- ```
15
+ ``` ruby
16
16
class PostSerializer < ActiveModel ::Serializer
17
17
attributes :id , :title , :body
18
18
end
@@ -23,7 +23,7 @@ into the serializer. Here's what you would do:
23
23
24
24
### posts_controller.rb
25
25
26
- ```
26
+ ``` ruby
27
27
...
28
28
def dashboard
29
29
render json: @posts , user_id: 12
@@ -33,7 +33,7 @@ into the serializer. Here's what you would do:
33
33
34
34
### posts_serializer.rb
35
35
36
- ```
36
+ ``` ruby
37
37
...
38
38
def comments_by_me
39
39
Comments .where(user_id: instance_options[:user_id ], post_id: object.id)
You can’t perform that action at this time.
0 commit comments