2017-05-01 36 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這一點。