1

回答用の質問を作成し、回答が正しい場合は 1 マークを設定しました..その列の合計が別のページに表示されます..助けてください

def next
@ans_id = 1
@user = current_user
@student = Student.find_by_admission_no(@user.username)
@exam_group = ExamGroup.find_by_id(params[:exam_group_id])
@answer = Answer.new(params[:ans])
@answer.answer = params[:answer]
@answer.exam_group_id = @exam_group.id
@answer.user_id = @user.id
passed_question = params[:passed_question]
@answer.questions_id = passed_question
@question = Question.find_by_id(passed_question)
if params[:answer] == @question.is_answer
  @answer.marks = 1
else
  @answer.marks = 0
end
if @answer.save
  @ans_id = @ans_id + answered.count
  @ans = Question.find_by_id(left_random, :conditions => ['id not in (?) && exam_group_id=?',answered, @exam_group])
  render(:update) do |page|
    page.replace_html 'main', :partial => 'ans', :object => @ans
  end
end
end

データベースは

+----+--------+--------------+---------+---------------+------------+-------+
| id | answer | questions_id | user_id | exam_group_id | modules_id | marks |
+----+--------+--------------+---------+---------------+------------+-------+
|  1 | ans1   |            1 |       3 |             1 |       NULL |     1 |
|  2 | ans2   |            2 |       3 |             1 |       NULL |     1 |
|  3 | ans3   |            3 |       3 |             1 |       NULL |     0 |
|  4 | ans2   |            4 |       3 |             1 |       NULL |     0 |
+----+--------+--------------+---------+---------------+------------+-------+

マーク列を合計して、そのコントローラーの別のページに表示したい

@exam_group = ExamGroup.find(params[:exam_group])
  @student = Student.find_by_id(params[:student])
  @batch = @student.batch
  @modules = StudentAdditionalField.find(:all)
  @total = Answer.sum(:marks)
  @exams = []
  @modules.each do |mod|
    @exams.push mod.name unless mod.name.nil?
    @exams.push mod.marks unless mod.marks.nil?
    @exams.push total unless total.nil?
  end

表示ビューは

      <% @exams.each do |es| %>
    <tr class="tr-<%= cycle('odd', 'even') %>">
      <td class="col-1"> <%= es.name %></td>
        <td class="col-1"><%= es.marks || '-' %></td>
        <% total_marks_attained = @total %>
        <td class="col-1"><%= es.marks %></td>
        <% total_max_marks = @total %>
      </td>
    </tr>
  <% end %>

事前に感謝します

4

1 に答える 1