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
5252end
5353Rails . configuration . serializers << CachingCommentSerializer
5454
55- class CachingPostSerializer < PostSerializer
55+ # see https://github.com/rails-api/active_model_serializers/pull/1690/commits/68715b8f99bc29677e8a47bb3f305f23c077024b#r60344532
56+ class CachingPostSerializer < ActiveModel ::Serializer
5657 cache key : 'post' , expires_in : 0.1 , skip_digest : true
58+
59+ attributes :id , :title , :body
60+
61+ has_many :comments , serializer : CommentSerializer
5762 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
6077end
6178Rails . configuration . serializers << CachingPostSerializer
6279
You can’t perform that action at this time.
0 commit comments