我一直在尝试保存具有多态关联的对象,请查看我的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>
如何保存具有多态关联的对象?感谢。
答案 0 :(得分:0)
我使用了以下修复来解决我的问题:
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这个。