0

jsonapi-utils (jsonapi-resources) requires a serializer (resource) for each ResourceController

Example
class FooController < JsonapiController
  def create
    # some code
  end
end

class BarController < JsonapiController
  def create
    # some code
  end
end

In this example BarController should use FooResource. Is it possible to define the serializer?

DenicioCode
  • 8,668
  • 4
  • 18
  • 33
  • I don't know if there is a less hacky way but you could define `def resource_klass_name; 'FooResource'; end;` in `BarController` This will override the original implementation [Source](https://github.com/cerebris/jsonapi-resources/blob/eb432722b915e76914be9132e010a1244a32e91c/lib/jsonapi/acts_as_resource_controller.rb#L164) – engineersmnky Jan 28 '21 at 22:00

1 Answers1

0

You can just specify the class manually by implementing the resource_class method:

class BarController < JsonapiController
  def create
    # some code
  end

  private

  def resource_klass
    @resource_class ||= FooResource
  end
end
max
  • 96,212
  • 14
  • 104
  • 165