我在控制器中創建一個數組以得到另一數據庫的值作爲錯誤在顯示陣列
@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
@modules的DATABSE是
+----+--------+-------+-------+
| id | name | total | marks |
+----+--------+-------+-------+
| 1 | Quants | 5 | 5 |
+----+--------+-------+-------+
應當顯示在視圖
<table id="listing" align="center" width="100%" cellpadding="1" cellspacing="1">
<tr class="tr-head">
<td><%#= t('subject') %></td>
<td><%= t('marks_obtained') %></td>
<td><%= t('max') %></td>
</td>
</tr>
<% @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 %>
<tr class="tr-head">
<td><%= t('total_marks') %>:</td>
<td><%= total_marks_attained %></td><td><%= total_max_marks %></td>
</tr>
</table>
但它返回錯誤爲undefined method 'Quants' for "Quants":String
。
請幫助我,在此先感謝。