Skip to content

Instantly share code, notes, and snippets.

@atstockland
Last active January 1, 2016 01:59
Show Gist options
  • Save atstockland/8076687 to your computer and use it in GitHub Desktop.
Save atstockland/8076687 to your computer and use it in GitHub Desktop.
Create a nested iteration that spans two table header rows. The idea is to have the upper row show the model aircraft, and then under that group show the school aircraft that are in that group.
<% @models.each_with_index do |m, index| %>
<th class="center-text model_column_span" colspan="<%= current_school.helicopters.active.joins{ helimodel }.where{ helimodel.nickname.eq( m ) }.order("helimodels.nickname asc").length %>"><%= m %></th>
<%= "(#{@models.length-1} - #{index}), " %>
<% if @models.length-1 == index %>
<%= "</tr> <tr>".html_safe %>
<% end %>
<th class="time">Time</th>
<% @aircraft.where{ helimodel.nickname.eq(m) }.each_with_index do |aircraft, column_index| %>
<th class="center-text" id="column_<%= column_index %>"><%= aircraft.name %></th>
<% end %>
<% end %>
This works. But, requires more code and only allows for styling the colspans in the top row...so, cant draw around both rows to section off the aircraft that go with the model.
<thead>
<tr>
<th></th>
<% @models.each do |m| %>
<th class="center-text model_column_span" colspan="<%= current_school.helicopters.active.joins{ helimodel }.where{ helimodel.nickname.eq( m ) }.order("helimodels.nickname asc").length %>"><%= m %></th>
<% end %>
</tr>
<tr>
<th class="time">Time</th>
<% @aircraft.each_with_index do |aircraft, column_index| %>
<th class="center-text" id="column_<%= column_index %>"><%= aircraft.name %></th>
<% end %>
</tr>
</thead>
@atstockland
Copy link
Author

I could just have two separate iterations over two separate tows. Which I already did...but, what Im after is the ability to style the blocks of aircraft and their associated aircraft model header.

@atstockland
Copy link
Author

Actually, I don't think is gonna do what I want...even if this worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment