I need to add a custom action to my jsonapi-resources controller. This action just creates e new version of a preexistent CollectorContent model instance. My implementation (just copied from here):
routes.rb
jsonapi_resources :collector_contents do
member do
post :create_version
end
end
collector_contents_controller.rb
class CollectorContentsController < ApplicationController
def create_version
cc = CollectorContent.find(params[:id])
cc_new_version = cc.create_version!
render json: resource_serializer.serialize_to_hash(CollectorContentResource.new(cc_new_version, nil))
end
end
Even if it works it seems that adding a new action in the controller is not the recommended way but I don't understand how I can use a operation processor to implement my use case. Can you help please?