Commit e83bd31dbd74f0518a75e5af4916827b4f9a47f5

Authored by Rafael Manzo
1 parent 62c67ea6

Refactored readingGroup show

Splited Reading listing into two partials

Signed off by: Guilherme Rojas V. de Lima <guilhermehrojas@gmail.com>
app/views/reading_groups/_no_readings.html.erb 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +<tr>
  2 + <% col_number = reading_groups_owner?(@reading_group.id) ? 5 : 3 %>
  3 + <td colspan="<%= col_number %>">There are no readings yet!</td>
  4 +</tr>
0 5 \ No newline at end of file
... ...
app/views/reading_groups/_reading.html.erb 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +<tr>
  2 + <td><%= reading.label %></td>
  3 + <td><%= reading.grade %></td>
  4 + <td style="background-color: #<%= reading.color %>; width: 20%;">&nbsp;</td>
  5 + <% if reading_groups_owner? @reading_group.id %>
  6 + <td>
  7 + <%= link_to 'Edit', edit_reading_group_reading_path(@reading_group.id, reading.id), class: 'btn btn-info' %>
  8 + </td>
  9 + <td>
  10 + <%= link_to 'Destroy', reading_group_reading_path(@reading_group.id, reading.id), method: :delete, data: { confirm: 'Are you sure that you want to destroy this reading?' }, class: 'btn btn-danger' %>
  11 + </td>
  12 + </td>
  13 + <% end %>
  14 +</tr>
0 15 \ No newline at end of file
... ...
app/views/reading_groups/show.html.erb
... ... @@ -25,26 +25,9 @@
25 25 <tbody>
26 26 <% reading_group_readings = @reading_group.readings %>
27 27 <% if reading_group_readings.size == 0 %>
28   - <tr>
29   - <% col_number = reading_groups_owner?(@reading_group.id) ? 5 : 3 %>
30   - <td colspan="<%= col_number %>">There are no readings yet!</td>
31   - </tr>
32   - <% end %>
33   - <% reading_group_readings.each do |reading| %>
34   - <tr>
35   - <td><%= reading.label %></td>
36   - <td><%= reading.grade %></td>
37   - <td style="background-color: #<%= reading.color %>; width: 20%;">&nbsp;</td>
38   - <% if reading_groups_owner? @reading_group.id %>
39   - <td>
40   - <%= link_to 'Edit', edit_reading_group_reading_path(@reading_group.id, reading.id), class: 'btn btn-info' %>
41   - </td>
42   - <td>
43   - <%= link_to 'Destroy', reading_group_reading_path(@reading_group.id, reading.id), method: :delete, data: { confirm: 'Are you sure that you want to destroy this reading?' }, class: 'btn btn-danger' %>
44   - </td>
45   - </td>
46   - <% end %>
47   - </tr>
  28 + <%= render partial: 'no_readings' %>
  29 + <% else %>
  30 + <%= render partial: 'reading', collection: reading_group_readings, as: :reading %>
48 31 <% end %>
49 32 </tbody>
50 33 </table>
... ...