Skip to content

Instantly share code, notes, and snippets.

@okuramasafumi
Created May 18, 2020 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okuramasafumi/b12cd0ab5b8bd195648fc93edea6f5fe to your computer and use it in GitHub Desktop.
Save okuramasafumi/b12cd0ab5b8bd195648fc93edea6f5fe to your computer and use it in GitHub Desktop.
ActiveModelSerializerのこう書きたい
class HogeSerializer < ActiveModel::Serializer
attributes :id, :hogehoge
has_many :fugas do |fuga|
fuga.attributes :id, :fugafuga
fuga.has_many :bars do |bar|
bar.attributes :id, :barbar
end
end
end
class HogeSerializer < ActiveModel::Serializer
attributes :id, :hogehoge
has_many :fugas
class FugaSerializer < ActiveModel::Serializer
attributes :id, :fugafuga
has_many :bars
class BarSerializer < ActiveModel::Serializer
attributes :id, :barbar
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment