Skip to content

Instantly share code, notes, and snippets.

@adavia
Created February 16, 2018 19:22
Show Gist options
  • Select an option

  • Save adavia/c17ba403e223653eea44f570e255c1b2 to your computer and use it in GitHub Desktop.

Select an option

Save adavia/c17ba403e223653eea44f570e255c1b2 to your computer and use it in GitHub Desktop.
AMS return obj association
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