Skip to content

Undefined method serialize_to_hash on Serializer page #53

@CodingItWrong

Description

@CodingItWrong

guide/serializer.html suggests that we can do:

post = Post.find(1)
JSONAPI::ResourceSerializer.new(PostResource).serialize_to_hash(PostResource.new(post, nil))

But when I do the equivalent in 0.10.2, I get the error:

undefined method `serialize_to_hash'
 for #<JSONAPI::ResourceSerializer:0x00007fae9ec1cbf0>

Looking through the source of JSONAPI::ResourceSerializer, #object_hash seems to be the currently-available method that meets that need. The code succeeds for me with the following change:

post = Post.find(1)
JSONAPI::ResourceSerializer.new(PostResource).object_hash(PostResource.new(post, nil), nil)

(Note that #object_hash takes two arguments, so we pass nil for the second.)

I would PR this change to the page, but I'm unsure of the correct changes for the rest of the page.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions