0
我目前多態關聯設置這樣Rails的多態關聯accepts_nested_attributes
class Reading < ApplicationRecord
has_one :audio, as: :audioable
accepts_nested_attributes_for :audio
end
class Audio < ApplicationRecord
belongs_to :audioable, polymorphic: true
end
在我RSPEC測試中,我有這樣的設置
@reading = attributes_for(:reading, creator: @user, body: "who let the dogs out? Must be me\n\nMeMeMe")
@reading[:audio_attributes] = attributes_for(:audio)
不過,我發佈這個時候遇到下面的錯誤@reading
到reading#create
控制器
{:errors=>{:"audio.audioable"=>["must exist"]}}
For非多態協會我已經得到它使用inverse_of
創建父和嵌套資源,但我不知道如何做多態關聯。