Created
February 16, 2018 19:22
-
-
Save adavia/c17ba403e223653eea44f570e255c1b2 to your computer and use it in GitHub Desktop.
AMS return obj association
This file contains hidden or 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 BookSerializer < ActiveModel::Serializer | |
| attributes :id, :title, :description, :created_by, :created_at | |
| has_many :comments | |
| def comments | |
| object.comments.index_by(&:id) # NoMethodError (undefined method `id' for [2]:Array): | |
| end | |
| end | |
| class CommentSerializer < ActiveModel::Serializer | |
| attributes :id, :content | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment