2

I am using the gem jsonapi-resources 0.10.5.

This is my resource:

class ProjectResource < JSONAPI::Resource
  attributes :name
end

and this is my controller:

class V2::ProjectController < V2::BaseController
    def index
        project = Project.find(1)
        JSONAPI::ResourceSerializer.new(ProjectResource).serialize_to_hash(ProjectResource.new(project, nil), nil) 
    end
end

and I get this error:

NoMethodError in V2::ProjectTypesController#index undefined method `serialize_to_hash' for #JSONAPI::ResourceSerializer:0x00007ffabcc336b0

I am just following the docs:

https://jsonapi-resources.com/v0.10/guide/serializer.html

Any idea what is wrong?

soltex
  • 2,993
  • 1
  • 18
  • 29
  • 2
    `serialize_to_hash` appears to exist in [master](https://github.com/cerebris/jsonapi-resources/blob/master/lib/jsonapi/resource_serializer.rb#L46) but not in [0.10.5](https://github.com/cerebris/jsonapi-resources/blob/v0.10.5/lib/jsonapi/resource_serializer.rb)? – engineersmnky Aug 11 '21 at 15:25
  • that makes sense, so why does the documentation says to add `gem 'jsonapi-resources'` to the Gemfile and then use `serialize_to_hash` if the version `0.10.5` doesn't contain that method? – soltex Aug 11 '21 at 15:32
  • 1
    Bad documentation? You could open an issue in git about this if you felt so inclined. – engineersmnky Aug 11 '21 at 16:02
  • Yeah, most probably. Could you please write an asnwer? I will be happy to upvote/accept your answer. – soltex Aug 11 '21 at 16:13

0 Answers0