hi I am new to rails pls need help.
Table data from index.html.erb
<table >
<thead>
<tr>
<th>Area</th>
<th>Item</th>
<th>Year</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<%@a1s.each do |ada| %>
<tr>
<td><%=ada.Area%></td>
<td><%=ada.Item%></td>
<td><%=ada.Year%></td>
<td><%=ada.Value%></td>
</tr>
<%end%>
</tbody>
</table>
how to change index.html.erb table to example converted table
- convert year data as a header and show their value.
- Item and Area names show ones and next country shown in next row.
CodePudding user response:
convert year data as a header and show their value.
You are looking for a list of all years in the data. You could do that, for example, with:
@a1s.map(&:Year).uniq
Item and Area names show ones and next country shown in next row.
I'd advise using .group_by
to organise the data for each row in the table.
<%@a1s.group_by(&:Area).each do |area, adas_in_area| %>
<