16 August 2020
Explicitly using ActiveModelSerializer
# serializers/product_serializer.rb
class ProductSerializer < ActiveModel::Serializer
end
# controller/product_controller.rb
...
serializer_options = {}
render json: ProductSerializer
.new(service_result.result.user_subscription, serializer_options)
.to_json,
status: :created
# controller/product_controller.rb
...
render json: {
data: ActiveModelSerializers::SerializableResource.new(
service.result,
{
each_serializer: ProductSerializer,
include_user_subscription: true,
include_package_subscriptions: true,
include_product: false,
include_package_subscription_details: false
}
),
meta: {
page: service.page,
per_page: service.per_page,
total_count: service.total_count,
total_pages: service.total_pages
}
}, status: :ok