我有以下帖子请求,我正在尝试获取团队 ID 值。
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"knq4dG1U/5NJxMD6KYxfOpKd3CuOBHRlp6xCwdpwCnQ=",
"match"=>{"name"=>"latest match",
"date(1i)"=>"2013",
"date(2i)"=>"5",
"date(3i)"=>"19",
"teams_attributes"=>{"0"=>{"name"=>"Navi",
"id"=>"1"},
"1369038961631"=>{"name"=>"A team",
"id"=>"2"}}},
"commit"=>"Update Match",
"match_id"=>"2"}
如果我这样做,那么我可以提取其中一个值的记录
params.first["match"]["teams_attributes"]["0"]["id"]
但我将处理一组“teams_attributes”,所以我正在执行这个循环,但它返回一个 nil 值。
teams = params.first["match"]["teams_attributes"] <---gets the teams_attributes array.
teams.each do |tea|
teamid = tea.first["id"]
puts teamid
end