以下PATCH操作获取以下参数
Parameters: {"utf8"=>"✓", [...], "contractgroup"=>
{"articolocontractgroups_attributes"=>
{"0"=>{"articolo_id"=>"0", "id"=>"425"},
"1"=>{"articolo_id"=>"true", "id"=>"426"},
"2"=>{"articolo_id"=>"true", "id"=>"427"},
"3"=>{"articolo_id"=>"0", "id"=>"428"}}, "contractgroup_id"=>"2"}, "commit"=>"Add"}
但是控制器操作是以错误的方式调用参数,因为没有创建记录:
params[:contractgroup][:articolocontractgroups_attributes].each do |id, attrs|
if params[:articolo_id] == "true"
@articolocontractgroup = Articolocontractgroup.new
(articolo_id: params[:contractgroup][:articolo_id],
contractgroup_id: params[:contractgroup][:contractgroup_id])
@articolocontractgroup.save
end
end
这搞砸了?
答案 0 :(得分:2)
您需要检查attrs[:articolo_id] == "true"
而不是params[:articolo_id]