我有一个 Ruby 哈希(最初是 rails 中的一个参数)
我如何计算correctness
每个中的数量answers_attributes
?
(我这样做的原因是我试图通过rails创建一个多项选择测验。一个问题可能有很多答案。我试图使用multi_correct
复选框来决定哪个问题有很多正确答案。但这有点违反直觉。所以我希望后端通过计算每个问题的正确性来决定)
{
"utf8" => "✓", "authenticity_token" => "r5xX46JG/GPF6+drEWmMPR+LpOI0jE0Tta/ABQ0rZJJE+UbbEjvNMLP6y2Z9IsWlXq27PR6Odx0EK4NECPjmzQ==", "question_bank" => {
"name" => "123213", "questions_attributes" => {
"0" => {
"content" => "question 1", "multi_correct" => "no", "answers_attributes" => {
"0" => {
"content" => "as1", "correctness" => "false"
}, "1" => {
"content" => "as2", "correctness" => "false"
}, "2" => {
"content" => "as3", "correctness" => "true"
}, "3" => {
"content" => "as4", "correctness" => "false"
}
}
}, "1" => {
"content" => "q2", "multi_correct" => "no", "answers_attributes" => {
"0" => {
"content" => "a1", "correctness" => "false"
}, "1" => {
"content" => "a2", "correctness" => "false"
}, "2" => {
"content" => "a3", "correctness" => "true"
}, "3" => {
"content" => "a4", "correctness" => "false"
}
}
}, "2" => {
"content" => "q3", "multi_correct" => "no", "answers_attributes" => {
"0" => {
"content" => "aa1", "correctness" => "false"
}, "1" => {
"content" => "aa2", "correctness" => "false"
}, "2" => {
"content" => "aa3", "correctness" => "false"
}, "3" => {
"content" => "aa4", "correctness" => "true"
}
}
}
}
}, "commit" => "Submit"
}