1
已經翻閱並嘗試了大多數例子,仍然無法創建工作HABTM。無論如何構建CaseTrack
和CaseTrackValue
工廠,我都無法在CaseTrack中找到CaseTrackValue[]
。不應在CaseTrack中正確創建CaseTrack提供CaseTrackValue參數。
BTW:HABTM的唯一工作關聯似乎是在CaseTrack中加入HABTM Association with FactoryGirl
case_track_values { |a| [a.association(:case_track_value)] }
。
class CaseTrack
has_and_belongs_to_many CaseTrackValue
end
class CaseTrackValue
has_and_belongs_to_many CaseTrack
end
Rspec
it 'may exercise the create action' do
post '<route>', params: {case_track: attributes_for(:case_track)}
end
end
class CaseTrackController < ApplicationController
private:
def case_track_params
params.require(:case_track).permit(:name, :active, {case_track_values:[]})
end
end