Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No serializer found for resource #2396

Open
rmcsharry opened this issue Oct 25, 2020 · 0 comments
Open

No serializer found for resource #2396

rmcsharry opened this issue Oct 25, 2020 · 0 comments

Comments

@rmcsharry
Copy link

rmcsharry commented Oct 25, 2020

I've scoured the closed issues and seen this occur many times, but it seems my case is unique.

What is especially weird is that my app still works for the subcategories despite the error in the log.

Expected behavior vs actual behavior

  1. Not to see
    [active_model_serializers] No serializer found for resource: #<Subcategory
    in my logs
    It appears 4 times always, twice each for the same two subcategories.
    (note the subcategories DO appear in the JSON response)

Steps to reproduce

Not sure I can reproduce it, but happy to give access to the repo.

These are the serializers:

class CategorySerializer < ActiveModel::Serializer
  attributes :id,
    :name
    
  has_many :subcategories
  has_many :category_attributes
end

class SubcategorySerializer < ActiveModel::Serializer
  attributes :id,
    :name

  belongs_to :category
end

class CategoryAttributeSerializer < ActiveModel::Serializer
  attributes :id,
    :name
    :value

  belongs_to :category
end

This is the controller action:

categories_controller.rb

  # GET /categories
  # GET /categories.json
  def index
    @categories = Category.all.includes(:subcategories, :category_attributes)
    render json: @categories, include: ['subcategories', 'category_attributes']
  end

Environment

ActiveModelSerializers Version (commit ref if not on tag):
gem 'active_model_serializers', '~> 0.10.0'

Output of ruby -e "puts RUBY_DESCRIPTION":
ruby 2.5.8p224 (2020-03-31 revision 67882) [x86_64-linux]

OS Type & Version:
MacOS Catalina

Integrated application and version (e.g., Rails, Grape, etc):
Rails 5.1.4

Backtrace

(e.g., provide any applicable backtraces from your application)
n/a

Additonal helpful information

The JSON response includes the subcategories, even though the log reports No serializer found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant