avrj/eventTicketing

View on GitHub
app/views/admin/customers/index.html.erb

Summary

Maintainability
Test Coverage
<h1 class="page-header">
  <span>Customers</span>
  <%= link_to new_admin_customer_path, class: "btn btn-primary pull-right" do %>
      <span class="glyphicon glyphicon-plus"></span> Add
  <% end %>
</h1>

<% if !@customers.any? %>
    <p>Looks like there are no customers yet.</p>
<% else %>
    <p>Total of <%= pluralize(@customers.count, "customer") %>.</p>
    <%= form_tag admin_customers_path, :method => :delete do %>
        <table class="table table-striped">
          <thead>
          <tr>
            <th></th>
            <th>Email</th>
            <th>Firstname</th>
            <th>Lastname</th>
            <th>Postcode</th>
            <th>City</th>
            <th>Age</th>
            <th>Gender</th>
            <th>Orders</th>
            <th></th>
          </tr>
          </thead>

          <tbody>
          <% @customers.each do |customer| %>
              <tr>
                <td><%= check_box_tag 'customer_ids[]', customer.id %></td>
                <td><%= customer.email %></td>
                <td><%= customer.firstname %></td>
                <td><%= customer.lastname %></td>
                <td><%= customer.postcode %></td>
                <td><%= customer.city %></td>
                <td><%= customer.date_of_birth %></td>
                <% if customer.gender == "male" %>
                    <td>M</td>
                <% elsif customer.gender == "female" %>
                    <td>F</td>
                <% else %>
                    <td>-</td>
                <% end %>
                <td><%= customer.reservations.count %></td>
                <td>
                  <!-- Split button -->
                  <div class="btn-group pull-right">
                    <%= link_to 'Show', admin_customer_path(customer), class: "btn btn-primary" %>
                    <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                      <span class="caret"></span>
                      <span class="sr-only">Toggle Dropdown</span>
                    </button>
                    <ul class="dropdown-menu" role="menu">
                      <li>
                        <%= link_to edit_admin_customer_path(customer) do %>
                            <span class="glyphicon glyphicon-edit"></span> Edit
                        <% end %>
                      </li>
                      <li>
                        <%= link_to admin_customer_path(customer), method: :delete, data: {confirm: 'Are you sure?'} do %>
                            <span class="glyphicon glyphicon-remove"></span> Remove
                        <% end %>
                      </li>
                    </ul>
                  </div>
                </td>
              </tr>
          <% end %>
          </tbody>
        </table>
        <%= submit_tag "Delete selected", class: "btn btn-danger", data: { confirm: "Are you sure?" } %>
    <% end %>
<% end %>