2

How can I add a new version of a resource without duplicating his related resources and controllers?

Lets say I have an API described by the following routing:

namespace :api do
  namespace :v1 do
    jsonapi_resources :contacts
    jsonapi_resources :phone_numbers
  end
end

class Api::V1::ContactResource < JSONAPI::Resource
  attributes :first_name, :last_name
  has_one :phone_number
end

I want to add new version of my ContactResource without duplicating the PhoneNumberResource and PhoneNumberController, is there a way to do something like:

class Api::V2::ContactResource < JSONAPI::Resource
  attributes :full_name
  has_one :phone_number, related_class: Api::V1::PhoneNumberResource
end

I'm working on a project with many related resources and I don't want to duplicate all of them, any suggestions?

kirlev
  • 680
  • 1
  • 7
  • 17

0 Answers0