rubyforgood/babywearing

View on GitHub
app/views/carriers/_list.html.erb

Summary

Maintainability
Test Coverage
<%= render 'shared/pagination', items: carriers %>
<table class="table">
  <thead>
    <tr class="super-header">
      <th scope="colgroup" colspan="5"></th>
      <th scope="colgroup" colspan="2" class="with-content">Location</th>
      <th scope="colgroup" colspan="100%"></th>
    </tr>
    <tr class="main-header">
      <th scope="col">Name</th>
      <th scope="col">Item ID</th>
      <th scope="col" title="Available">Avail</th>
      <th scope="col">Manufacturer</th>
      <th scope="col">Model</th>
      <th scope="col">Current</th>
      <th scope="col">Home</th>
      <th scope="col">Category</th>
      <th scope="col">State</th>
      <th scope="col"></th>
    </tr>
  </thead>
  <tbody>
    <% if carriers.empty? %>
      <tr>
        <td colspan="100%">No carriers to show</td>
      </tr>
    <% else %>
      <% carriers.each do |carrier| %>
        <tr>
          <td><%= link_to carrier.name, carrier_path(carrier)  %>
          <td><%= carrier.item_id %></td>
          <td><%= carrier.available? ? fa_icon('check-circle') : fa_icon('stop-circle') %></td>
          <td><%= carrier.manufacturer %></td>
          <td><%= carrier.model %></td>
          <td><%= carrier.current_location.name %></td>
          <td><%= carrier.home_location.name %></td>
          <td><%= carrier.category.name %></td>
          <td><%= carrier.state.titleize %></td>
          <td>
            <% can_destroy =  policy(carrier).destroy? %>
            <% can_edit =  policy(carrier).edit? %>
            <% if can_destroy || can_edit %>
              <div class="actions">
                <%= link_to 'Edit', edit_carrier_path(carrier), class: 'btn btn-primary btn-sm' if policy(carrier).edit? %>
                <%= link_to 'Destroy', carrier, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger btn-sm' %>
              </div>
            <% end %>
          </td>
        </tr>
      <% end %>
    <% end %>
  </tbody>
</table>