Created
May 18, 2020 12:54
-
-
Save okuramasafumi/b12cd0ab5b8bd195648fc93edea6f5fe to your computer and use it in GitHub Desktop.
ActiveModelSerializerのこう書きたい
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 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 |
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 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