File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -52,11 +52,28 @@ class CachingCommentSerializer < CommentSerializer
52
52
end
53
53
Rails . configuration . serializers << CachingCommentSerializer
54
54
55
- class CachingPostSerializer < PostSerializer
55
+ # see https://github.com/rails-api/active_model_serializers/pull/1690/commits/68715b8f99bc29677e8a47bb3f305f23c077024b#r60344532
56
+ class CachingPostSerializer < ActiveModel ::Serializer
56
57
cache key : 'post' , expires_in : 0.1 , skip_digest : true
58
+
59
+ attributes :id , :title , :body
60
+
61
+ has_many :comments , serializer : CommentSerializer
57
62
belongs_to :blog , serializer : BlogSerializer
58
- belongs_to :author , serializer : CachingAuthorSerializer
59
- has_many :comments , serializer : CachingCommentSerializer
63
+ belongs_to :author , serializer : AuthorSerializer
64
+
65
+ link ( :post_authors ) { 'https://example.com/post_authors' }
66
+
67
+ meta do
68
+ {
69
+ rating : 5 ,
70
+ favorite_count : 10
71
+ }
72
+ end
73
+
74
+ def blog
75
+ Blog . new ( id : 999 , name : 'Custom blog' )
76
+ end
60
77
end
61
78
Rails . configuration . serializers << CachingPostSerializer
62
79
You can’t perform that action at this time.
0 commit comments