Skip to content

uninitialized constant GroupsController::SerializableGroup #114

Open
@chrisgeek

Description

Hi, I am trying to switch from AMS to jsonapi-rails gem, but after creating serializers, I still get an uninitialized constant GroupsController::SerializableGroup error message from the gem

def index
    groups = Group.all
    render jsonapi: groups, class: {Group: SerializableGroup } 
end

serializers/group_serializer.rb

class SerializableGroup < JSONAPI::Serializable::Resource
  type 'group'
  has_many :users
  attributes :name
end

I'm not sure what I am doing wrong really.

Activity

beauby

beauby commented on Feb 5, 2020

@beauby
Member

Could you try replacing class: {Group: SerializableGroup } with class: {Group: ::SerializableGroup } ?

chrisgeek

chrisgeek commented on Feb 5, 2020

@chrisgeek
Author

Thanks for your response, tried what you suggested but I got the same error message.

matt-glover

matt-glover commented on Mar 30, 2020

@matt-glover

Maybe a Rails autoloading thing? Is there a require in the controller for the serializers/group_serializer file?

Based on the original issue it looks like the name of the file (serializers/group_serializer.rb) does not match the name of the class (SerializableGroup) both because of the ordering of terms group and serializable and because the file name is serializers while the class says Serializable so the Rails autoloader might not be able to find and load that class dynamically.

JohnFTitor

JohnFTitor commented on Jun 4, 2022

@JohnFTitor

I had the same issue. Changed the name of the file to match the new Serializable class (Like this: serializable_equipment for the class: SerializableEquipment) and it worked for me.

It is as @matt-glover implied. A rails autoloading thing with the filename

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      uninitialized constant GroupsController::SerializableGroup · Issue #114 · jsonapi-rb/jsonapi-rails