How can I fetch the data related the specific object with JSON-API-Resources.
Within controller,
module Api
module V1
class SubscriptionsController < Api::V1::ApiController
def create
@plan = Plan.find_by(id: plan_id_param)
@result = Creditcard::CreateSubscription.call(@plan, params_ex: foo)
if @result.errors.blank?
resource = Api::V1::SubscriptionResource.new(@result, nil)
serializer = JSONAPI::ResourceSerializer.new(Api::V1::SubscriptionResource)
json_body = serializer.serialize_to_hash(resource)
render json: json_body, status: 200 # :ok
Usually, we can do
def show
params[:include] = "relation1.relation2.relation3" if params[:include].nil?
super
end
And it's done.
But in this case, this is JSONAPI::SubscriptionResource
object.
How can I show relations of the object?