Skip to content

Commit 0ed771a

Browse files
author
Theresa
committed
Beautify cart view
1 parent 7813b6e commit 0ed771a

File tree

13 files changed

+39
-169
lines changed

13 files changed

+39
-169
lines changed

app/views/carts/_form.html.erb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,23 @@
1111
</div>
1212
<% end %>
1313

14-
<div class="field">
15-
<%= f.label :user_id %><br>
16-
<%= f.text_field :user_id %>
17-
</div>
14+
<% if @cart.persisted?%>
15+
<dl class="dl-horizontal">
16+
<dt>Exercises</dt>
17+
<% if @cart.user === current_user %>
18+
<% if @cart.exercises %>
19+
<% @cart.exercises.each do |exercise| %>
20+
<dd><%= link_to exercise.title, exercise_path(exercise) %></dd>
21+
<dd><%= link_to 'Delete', nil, class:'btn btn-danger btn-xs' %></dd>
22+
<% end %>
23+
<% else%>
24+
<dd> <%= 'No exercises added' %></dd>
25+
<% end %>
26+
<% end %>
27+
</dl>
28+
<% end %>
29+
1830
<div class="actions">
19-
<%= f.submit %>
31+
<%= f.submit nil, class:'btn btn-primary' %>
2032
</div>
2133
<% end %>

app/views/carts/edit.html.erb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
<%= render 'form' %>
44

5-
<%= link_to 'Show', @cart %> |
6-
<%= link_to 'Back', carts_path %>
5+
<%= link_to 'Back', :back, class:'btn btn-default btn-xs' %>

app/views/carts/index.html.erb

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
<p id="notice"><%= notice %></p>
22

3-
<h1>Listing Carts</h1>
3+
<h2>Your Cart <%= link_to 'New Cart', new_cart_path, class:'btn btn-success' %></h2>
44

5-
<table>
6-
<thead>
7-
<tr>
8-
<th>User</th>
9-
<th colspan="3"></th>
10-
</tr>
11-
</thead>
125

13-
<tbody>
14-
<% @carts.each do |cart| %>
15-
<tr>
16-
<td><%= cart.user %></td>
17-
<td><%= link_to 'Show', cart %></td>
18-
<td><%= link_to 'Edit', edit_cart_path(cart) %></td>
19-
<td><%= link_to 'Destroy', cart, method: :delete, data: { confirm: 'Are you sure?' } %></td>
20-
</tr>
21-
<% end %>
22-
</tbody>
23-
</table>
6+
<dl class="dl-horizontal">
7+
<dt>Exercises</dt>
8+
<% @carts.each do |cart| %>
9+
<% if cart.user === current_user %>
10+
<% if cart.exercises %>
11+
<% cart.exercises.each do |exercise| %>
12+
<dd><%= link_to exercise.title, exercise_path(exercise) %></dd>
13+
<% end %>
14+
<% else%>
15+
<dd> <%= 'No exercises added' %></dd>
16+
<% end %>
17+
<% end %>
18+
<dt>Actions</dt>
19+
<dd><%= link_to 'Edit', edit_cart_path(cart), class:'btn btn-warning btn-xs' %> <%= link_to 'Destroy', cart, method: :delete, data: { confirm: 'Are you sure?' }, class:'btn btn-danger btn-xs' %></dd>
20+
<% end %>
21+
</dl>
2422

25-
<br>
2623

27-
<%= link_to 'New Cart', new_cart_path %>
24+
<br>

app/views/carts/show.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<p id="notice"><%= notice %></p>
22

33
<p>
4-
<strong>User:</strong>
5-
<%= @cart.user %>
4+
<strong>Exercise:</strong>
5+
<%= @cart.exercises %>
66
</p>
77

88
<%= link_to 'Edit', edit_cart_path(@cart) %> |

app/views/layouts/application.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<%= menu_group pull: :right do %>
3232
<% if current_user %>
3333
<% if current_user.cart %>
34-
<%= menu_item 'Cart (' + current_user.cart_count.to_s + ')', cart_path(current_user.cart) %>
34+
<%= menu_item 'Cart (' + current_user.cart_count.to_s + ')', carts_path %>
3535
<% end %>
3636
<%= menu_item current_user.email, user_path(current_user) %>
3737
<%= menu_item 'Log out', logout_path, method: :delete %>

spec/views/carts/edit.html.erb_spec.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

spec/views/carts/index.html.erb_spec.rb

Lines changed: 0 additions & 19 deletions
This file was deleted.

spec/views/carts/new.html.erb_spec.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

spec/views/carts/show.html.erb_spec.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

spec/views/collections/edit.html.erb_spec.rb

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)