在show
视图中,我想显示所有多项选择问题和答案,并为每个问题添加correct-answer
,incorrect-answer
和normal-answer
的css类显示答案以表示答案是1.用户正确回答2.用户未正确回答,或3.完全没有回答(用户选择了另一个答案选项)。在我的代码中,@submitted_quiz.submitted_answers
包含用户输入的所有答案。
<% question.answers.each do |answer| %>
<% @submitted_quiz.submitted_answers.each do |submitted_answer| %>
<% if(submitted_answer.content == answer.content && submitted_answer.question.id == answer.question.id && submitted_answer.got_correct) %>
<li><span class ='correct-answer'><%= answer.content %> CORRECT </span></li>
<% elsif(submitted_answer.content == answer.content && submitted_answer.question.id == answer.question.id && submitted_answer.got_incorrect) %>
<li><span class ='incorrect-answer'><%= answer.content %> INCORRECT</span></li>
<% else %>
<li><span class ='normal-answer'> <%= answer.content %> NORMAL</span></li>
<% end # if statement%>
<% end # submitted_answers.each do%>
<% end # question.answers.each do |answer|%>
我知道我做错了什么,但我似乎无法修复它。有什么想法吗?