nilbus/pinewood-derby

View on GitHub
app/views/contestants/index.html.erb

Summary

Maintainability
Test Coverage
<h1>Contestants</h1>

<table id="contestants">
  <% if @contestants.any? %>
    <thead>
      <tr>
        <th>Rank</th>
        <th>Name</th>
        <th>Average</th>
        <% DerbyConfig.lane_count.times do |i| %>
          <th>Round <%= i+1 %></th>
        <% end %>
        <th></th>
      </tr>
    </thead>
  <% end %>

  <tbody>
    <% i = 0 %>
    <%= content_tag_for(:tr, @contestants, class: "contestant") do |contestant| %>
      <td class="rank">
        <%= i += 1 if contestant.average_time %>
      </td>
      <td class="<%= 'retired' if contestant.retired %>">
        <% if admin? %>
          <%= link_to contestant.name, edit_contestant_path(contestant) %>
        <% else %>
          <%= contestant.name %>
        <% end %>
      </td>
      <td>
        <%= contestant.average_time %>
      </td>
      <% DerbyConfig.lane_count.times do |i| %>
        <td><%= contestant.runs.complete[i].try :time %></td>
      <% end %>
      <td>
        <% if contestant.retired %>
          <%= link_to 'reactivate', reactivate_contestant_path(contestant), method: :post, class: 'retire', style: 'display: none' %>
        <% else %>
          <%= link_to 'retire', contestant, method: :delete, data: { confirm: "Are you sure? #{j contestant.name} will be taken out of the race." }, class: 'retire', style: 'display: none' %>
        <% end %>
      </td>
    <% end %>
  </tbody>
</table>

<br>

<% if admin? %>
  <%= link_to 'Register contestants', new_contestant_path, class: 'btn btn-primary' %>
  <%= link_to 'Reset derby', reset_derby_path, class: 'btn btn-danger pull-right', method: 'post', data: { confirm: 'Are you sure? This will clear out all data and start a new derby.' } %>
<% end %>