2017-05-01 35 views
0

我一直在努力节省谁拥有多态关联一个对象,看看我的create_params态关联:API规范

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

拿我的整个堆栈掠夺https://gist.github.com/brunowego/33da32291a05a486f512965b2c41134c –

回答

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这一点。