使用 JSON:API 规范与 AMS 的多态关联

Polymorphic association with AMS using JSON:API specification

我一直在尝试保存一个具有多态关联的对象,看看我的create_params:

module Admin
  class ChatroomsController < AdminController # :nodoc:
    ...

    def create_params
      ActiveModelSerializers::Deserialization.jsonapi_parse!(
        params,
        only: [:name, :chatable],
        polymorphic: [:chatable]
      )
    end
  end
end

发送保存时,AMS 找不到解析模型名称的方法:

#<NameError: wrong constant name disputes>

如何保存具有多态关联的对象?谢谢

我使用了以下修复程序来解决我的问题:

module Admin
  class ChatroomsController < AdminController # :nodoc:
    ...

    def create_params
      res = ActiveModelSerializers::Deserialization.jsonapi_parse!(
        params,
        only: [:name, :chatable],
        polymorphic: [:chatable]
      )
      res[:chatable_type] = res[:chatable_type].singularize.capitalize
      res
    end
  end
end

AMS have a pull request to solve 这个.