在控制器中止时,这是我从 Ajax 调用中获得的 javascript 对象的格式:
{
"j_identifier" = > "24942",
"charge" = > {
"0" = > {
"complainant" = > "",
"address" = > "",
"name" = > "",
"agency" = > "",
"codefendant" = > {
"0" = > {
"name" = > "sdfsdsd",
"address" = > "fsdf",
"phone" = > "sdf"
},
"1" = > {
"name" = > "sdfs",
"address" = > "sdfs",
"phone" = > "sdf"
}
}
},
"1" = > {
"complainant" = > "",
"address" = > "",
"name" = > "",
"agency" = > "",
"codefendant" = > {
"0" = > {
"name" = > "sdfsdsd",
"address" = > "fsdf",
"phone" = > "sdf"
},
"1" = > {
"name" = > "sdfs",
"address" = > "sdfs",
"phone" = > "sdf"
}
}
}
}
}
这就是我正在做的获取数据并保存它:
jcharge = params[:charge]
if !jcharge.nil?
jcharge.each do |key,charge|
e = JCharge.new(charge)
e.cmap_id = data.id
e.save
charge_id = e.id
codefd = charge.codefendant
if !codefd.nil?
codefd.each do |k,codef|
cod = JuCharge.new(codef)
cod.jucharge_id = data.id
cod.save
end
end
end
end
我收到此解析错误:
undefined method `codefendant' for #<ActiveSupport::HashWithIndifferentAccess:0x44b5ab0>