rails: how to divide data into separate td's after x records
At the moment I have the following in my view (I know it's ugly, I'm only
doing this so everything is on the same page while I test, I'll clean it
up when it works!):
<div class="holder2 round">
<% if @goal.avg.nan? %>
<p>
This goal has not been evaluated yet!
</p>
<% else %>
<%= render 'evaluations_by_goal' %>
<% end %>
</div>
_evaluations_by_goal.html.erb:
<% ordered_evals_by_goal =
@goal.evaluations.order("eval_number").all.group_by { |g| g.eval_number }
%>
<h3>
The overall average for this goal is <%= @goal.avg %>
</h3>
<table>
<tr>
<th>Student Name</th>
<th>Evaluation 1</th>
<th>Evaluation 2</th>
</tr>
<% @scores = [] %>
<% ordered_evals_by_goal.each do |number, evals| %>
<% evals.in_groups(evals.count, false) do |group| %>
<% group.each do |eval| %>
<tr>
<td><%= eval.student.name %></td>
<td><%= eval.score %></td>
<td>**others here**</td>
</tr>
<% end %>
<% end %>
<% end %>
</table>
Edit:
so you can see the structure of the hash, ordered_evals_by_goal outputs this:
{22=>
[#<Evaluation id: 1702, score: 4, created_at: "2013-08-25 11:00:58",
updated_at: "2013-08-25 11:00:58", student_id: 22, goal_id: 28,
eval_number: 22>,
#<Evaluation id: 1710, score: 3, created_at: "2013-08-25 11:01:08",
updated_at: "2013-08-25 11:01:08", student_id: 23, goal_id: 28,
eval_number: 22>,
#<Evaluation id: 1718, score: 3, created_at: "2013-08-25 11:01:15",
updated_at: "2013-08-25 11:01:15", student_id: 24, goal_id: 28,
eval_number: 22>,
#<Evaluation id: 1726, score: 3, created_at: "2013-08-25 11:01:21",
updated_at: "2013-08-25 11:01:21", student_id: 25, goal_id: 28,
eval_number: 22>],
23=>
[#<Evaluation id: 1734, score: 3, created_at: "2013-08-25 11:02:18",
updated_at: "2013-08-25 11:02:18", student_id: 22, goal_id: 28,
eval_number: 23>,
#<Evaluation id: 1742, score: 3, created_at: "2013-08-25 11:02:27",
updated_at: "2013-08-25 11:02:27", student_id: 23, goal_id: 28,
eval_number: 23>,
#<Evaluation id: 1750, score: 3, created_at: "2013-08-25 11:02:35",
updated_at: "2013-08-25 11:02:35", student_id: 24, goal_id: 28,
eval_number: 23>,
#<Evaluation id: 1758, score: 3, created_at: "2013-08-25 11:02:42",
updated_at: "2013-08-25 11:02:42", student_id: 25, goal_id: 28,
eval_number: 23>]}
End edit
At the moment, it outputs this:
But where the student names begin to loop, i want the score data to go
into the empty td so that the whole table is (in this case) 5 rows all
together - one of table header and four of table data. How can I do this?
No comments:
Post a Comment