My application has following versions: rails 6.0.0
, ruby 2.6.3
.
I have around 20 controllers in the application and we have planned to use fast-json-api
instead of rabl
as serializer in the app. I found the number of serializer files growing very fast for each controller. (screenshot below).
Questions
Is there a better way to organise all the serializers?
I have tried the following 2 ways to organise:
Organizing all serializers of one controller under its model-name (like rabl)
But it gave me this error:
NameError (uninitialized constant Api::V1::LexiconsController::ListNodeSerializer)
Can I render different api view in single Serializer, by keeping all the SerializerClassNames in the same serialzer file for that controller??
Serializer for Category Controller
class ShowSerializer < ApplicationSerializer
cache_options enabled: true, cache_length: 24.hours
attributes :name, :status, :description
end
class IndexSerializer < ApplicationSerializer
attributes :name, :status, :thumbnail, :definition
attributes :area do |area|
area.country.try(:name).try(:html_safe)
end
end