sanger/sequencescape

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

Summary

Maintainability
Test Coverage

<% unless submissions.empty? %>
  <table class='sortable'>
    <thead>
      <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Created at</th>
        <th></th>
        <% if can? :edit, Submission %>
          <th></th>
        <% end %>
        <% if can? :delete, Submission %>
          <th></th>
        <% end %>
      </tr>
    </thead>
    <% submissions.each do |submission| %>
      <tr>
        <td><%= link_to submission.id, submission_path(submission) %></td>
        <td><%= submission.name %></td>
        <td><%= submission.created_at.to_formatted_s(:day_full_with_time) %></td>
        <td><%= link_to "View", submission_path(submission) %></td>
        <% if can? :edit, Submission %> <%# Render the cell if you can edit *any* submission %>
          <td>
            <% if can?(:delete, submission) && submission.editable? %> <%# But only show the link if you can edit THIS submission%>
              <%= link_to("Edit", edit_submission_path(submission)) %>
            <% end %>
          </td>
        <% end %>
        <% if can?(:delete, Submission) %> <%# Render the cell if you can delete *any* submission %>
          <td>
            <% if can?(:delete, submission) & submission.destroyable? %> <%# But only show the link if you can delete THIS submission%>
              <%= link_to("Delete", submission_path(submission), method: :delete, confirm: "Are you sure?") %>
            <% end %>
          </td>
        <% end %>
      </tr>
    <% end %>
    </table>
<% else %>
  <p>You currently have no submissions in this state.</p>
<% end %>