<h1> What it looks like currently</h1><br>
<table>
<thead>
<tr>
<th>Month</th>
<th>Month Total</th>
<th>Written</th>
<th>Verbal</th>
<th>Probable 75%</th>
<th>Probable 25%</th>
<th>Speculative</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<tr><td>Jan 2017</td> <td>50</td><td>0</td><td>50</td><td>0</td><td>0</td><td>0</td></tr>
<tr> <td>Feb 2017</td> <td>100</td><td>0</td><td>100</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>Mar 2017</td> <td>700</td><td>0</td><td>700</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>Jan 2017</td> <td>700</td><td>700</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>Feb 2017</td> <td>5000</td><td>5000</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>Jan 2017</td> <td>500</td><td>0</td><td>0</td><td>500</td><td>0</td><td>0</td></tr>
<tr><td>Jan 2017</td> <td>5000</td><td>0</td><td>0</td><td>0</td><td>0</td><td>5000</td></tr>
</tbody>
</table>
<h1> What I need it look like </h1><br>
<table>
<thead>
<tr>
<th>Month</th>
<th>Month Total</th>
<th>Written</th>
<th>Verbal</th>
<th>Probable 75%</th>
<th>Probable 25%</th>
<th>Speculative</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<tr><td>Jan 2017</td> <td>1250</td><td>700</td><td>50</td><td>500</td><td>0</td><td>5000</td></tr>
<tr> <td>Feb 2017</td> <td>5100</td><td>5000</td><td>100</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>Mar 2017</td> <td>700</td><td>0</td><td>700</td><td>0</td><td>0</td><td>0</td></tr>
</tbody>
</table>
I'm a bit of a coding noob so I could be going about this all the wrong way, but I've muddled my way through so far...until now.
What I need is to subtotal the months so the values all appear on the relevant line: Here
The code I used for that is:`
<% @months.each do |t| %>
<tr>
<td><%= t.monthYear %> </td> <td><%= t.monthValue %></td>
<% if(t.destination.status == "Written") %>
<td><%= t.monthValue %></td>
<% else %>
<td>0</td>
<% end %>
<% if(t.destination.status == "Verbal") %>
<td><%= t.monthValue %></td>
<% else %>
<td>0</td>
<% end %>
<% if(t.destination.status == "Probable 75%") %>
<td><%= t.monthValue %></td>
<% else %>
<td>0</td>
<% end %>
<% if(t.destination.status == "Probable 25%") %>
<td><%= t.monthValue %></td>
<% else %>
<td>0</td>
<% end %>
<% if(t.destination.status == "Speculative") %>
<td><%= t.monthValue %></td>
<% else %>
<td>0</td>
<% end %>
</tr>
<% end %>`
The models:
Destination:
class Destination < ActiveRecord::Base
belongs_to :tag
has_many :months
end
Month:
class Month < ActiveRecord::Base
belongs_to :destination
belongs_to :tag
end
The months have 3 fields: monthYear, monthValue & Destination_id.
Destination has Status and others which I don't think are relevant.
I've been searching and used:
% @months.select(:monthYear, :monthValue, :destination_id).group(:monthYear).each do |t| %>
and different variations including trying to sum by :monthValue but end up with this: Subtotaled months but not values.
Thanks in advance!