Reputation: 2354
I inherited a JSONAPI::Processor from 2017 (now is Jul/2023):
module Api
module V2
class GivingNumberSearchProcessor < JSONAPI::Processor
def create_resource
data = params[:data]
search = GivingNumberSearch.new(
country: data[:attributes][:country],
area_code: data[:attributes][:area_code]
)
search.execute
resource = GivingNumberSearchResource.new(search, context)
JSONAPI::ResourceOperationResult.new(:created, resource)
end
end
end
end
search.execute returns an array of ActiveRecord objects.
Apparently JSONAPI::ResourceOperationResult changed to JSONAPI::ResourceSetOperationResult. But after upgraded the name I'm getting:
"undefined method `resource_klasses' for #\u003cApi::V2::GivingNumberSearchResource
"backtrace":["/home/xpsman/.rvm/gems/ruby-3.0.6/gems/jsonapi-resources-0.10.7/lib/jsonapi/resource_serializer.rb:51
I found the create_resource method. It seems I'm missing a step to add the "resource_klasses" part before passing the value to the serializar, but is my first week with JSONAPI::Resources.
# file: app/resources/api/v2/giving_number_search_resource.rb
module Api
module V2
class GivingNumberSearchResource < JSONAPI::Resource
attributes :area_code, :country
has_many :inbound_numbers
end
end
end
Upvotes: 0
Views: 34