我在控制器中创建了一个数组来获取另一个数据库的值
@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 的数据库是
+----+--------+-------+-------+
| 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
.
请帮助我,在此先感谢。