I need to create a structure like that using the active_model_serializers gem
{
"categories": [
{
"code": "code",
"name": "name"
},
{
"code": "code",
"name": "name"
},
{
"code": "code",
"name": "name"
},
{
"code": "code",
"name": "name"
}
]
}
Categories refers to a PORO virtus:
module Api
module Bitsky
class MarketStructure
include Virtus.model
attribute :department_name, String
attribute :department_code, Integer
attribute :department_value, String
attribute :sector_name, String
attribute :sector_code, Integer
attribute :sector_value, String
attribute :family_name, String
attribute :family_code, Integer
attribute :family_value, String
attribute :sub_family_name, String
attribute :sub_family_code, Integer
attribute :sub_family_value, String
end
end
end
I've code this serializer to try to create that hash. It worked, however the result was not what I expected.
module Api
module Bitsky
class MarketStructure< ActiveModel::Serializer
attributes :categories
def categories
*** some operation ***
end
end
end
end
Result
{
"categories": {
"categories": [
{
"code": "code",
"name": "name"
}
]
}
}
How do I write a serializer which return only a Hash Array without this key "categories" ?