Sto cercando più array ma ho problemi con l'allineamento in una tabella in base all'anno. Al momento i dati non si allineano con l'anno corrispondente, se i dati esistono in qualsiasi anno, si limitano a collocare i dati nella prima riga, quindi posiziona i dati '0' per il resto, ad es. non allineato con l'anno.Loop di più array per anno
View
<table>
<% @a.zip(@b, @c, @d) do |a, b, c, d| %>
<tr>
<td><%= a.year %></td>
<% if a.blank? %>
<td>0</td>
<td>0</td>
<% else %>
<td><%= a.id %></td>
<td><%= a.data %></td>
<% end %>
<% if b.blank? %>
<td>0</td>
<td>0</td>
<% else %>
<td><%= b.id %></td>
<td><%= b.data %></td>
<% end %>
<% if c.blank? %>
<td>0</td>
<td>0</td>
<% else %>
<td><%= c.id %></td>
<td><%= c.data %></td>
<% end %>
<% if d.blank? %>
<td>0</td>
<td>0</td>
<% else %>
<td><%= d.id %></td>
<td><%= d.data %></td>
<% end %>
</tr>
</table>
controller
@a = Result.where(id: params[:id_select]).group('year').where('data > 0').select('AVG(data) AS data, year as year, COUNT(id) AS id').order('year ASC')
@b = Result.where(id: params[:id_select]).group('year').where('data > 0').select('AVG(data) AS data, year as year, COUNT(id) AS id').where('id = ?', '0').order('year ASC')
@c = Result.where(id: params[:id_select]).group('year').where('data > 0').select('AVG(data) AS data, year as year, COUNT(id) AS id').where('id = ?', '1').order('year ASC')
@d = Result.where(id: params[:id_select]).group('year').where('data > 0').select('AVG(data) AS data, year as year, COUNT(id) AS id').where('id = ?', '2').order('year ASC')
Gentilmente parlare formato dei dati nel formato tavolo e output che si desidera. – seahawk
ho alcuni problemi nel trovare ciò che la domanda vuole, puoi scrivere i dati che hai esplicitamente ** non le query ** e il formato che vuoi nel testo. –
@DollarChills, ho proposto una soluzione al tuo problema di seguito. Spero di aver capito bene. Fammi sapere se si adatta alle tue esigenze. – dimakura