-
-
Save mmun/3646b88d4cb2f13a256b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
def index | |
render @blogs, shallow: true | |
end | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BlogSerializer < ActiveModel::Serializer | |
attributes :id, :title | |
has_many :posts | |
def posts_serializer_options | |
if @options[:shallow] | |
{ hide_comments: true } | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostSerializer < ActiveModel::Serializer | |
attributes :id, :title, :body | |
has_many :comments | |
def include_comments? | |
!@options[:hide_comments] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CommentSerializer < ActiveModel::Serializer | |
attributes :id, :body | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment