Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Serializer concerns not being loaded #2091
Expected behavior vs actual behavior
I have an versioned Rails API application using concerns to bundle shared functionality between multiple serializers. I would expect namespaced serializer concerns to load properly, similar to how namespaced controller concerns work. However, when I namespace a serializer concern, it encounters an uninitialized constant exception. I believe the concern files aren't being loaded at all by by Active Model Serializers. Is there something I am missing to set this up properly?
Steps to reproduce
class ApplicationSerializer < ActiveModel::Serializer # Shared functionality end
module V2 class PersonaSerializer < ApplicationSerializer include V2::ClaimableSerializer # Other serializer attributes / methods end end
module V2 module ClaimableSerializer extend ActiveSupport::Concern included do # Shared attributes to be included with this concern end end end
ActiveModelSerializers Version 0.10.5
I'm going to close this because its a Ruby issue, possibly resolvable by modifying the autoload paths in Rails, and not an AMS issue. Please feel free to continue discussing though.
you probably want to add
Rails.application.configure do config.paths.add "app/serializers/concerns", eager_load: true end
@bf4 Thanks, that led me to finding the solution.
Old Directory Structure
New Directory Structure