Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

how to display the has_many in the api serializer rails

class ProjectGroupSerializer < ActiveModel::Serializer
  attributes :id, :name, :description, :projects

  def projects
    object.projects.map do |project|
      ::ProjectSerializer.new(project).attributes
    end
  end
end
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #display #api #serializer #rails
ADD COMMENT
Topic
Name
4+4 =