diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss
index e44cefb..f2773a6 100644
--- a/app/assets/stylesheets/application.scss
+++ b/app/assets/stylesheets/application.scss
@@ -6,7 +6,7 @@
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
- * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
+ * compiled file so the styles you ad=d here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
@@ -60,6 +60,25 @@
padding: 1em 2em;
background: #141;
+ form, div {
+ display: inline;
+ }
+
+ input {
+ font-size: small;
+ }
+
+ #cart {
+ font-size: smaller;
+ color: white;
+
+ table {
+ border-top: 1px dotted #595;
+ border-bottom: 1px dotted #595;
+ margin-bottom: 10px;
+ }
+ }
+
ul {
padding: 0;
diff --git a/app/assets/stylesheets/carts.scss b/app/assets/stylesheets/carts.scss
index fe0ac50..4dbe7ba 100644
--- a/app/assets/stylesheets/carts.scss
+++ b/app/assets/stylesheets/carts.scss
@@ -1,7 +1,7 @@
// Place all the styles related to the Carts controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
-.carts {
+.carts, #side #cart {
.item_price, .total_line {
text-align: right;
}
diff --git a/app/controllers/carts_controller.rb b/app/controllers/carts_controller.rb
index c4227ab..36a3270 100644
--- a/app/controllers/carts_controller.rb
+++ b/app/controllers/carts_controller.rb
@@ -30,7 +30,7 @@ class CartsController < ApplicationController
respond_to do |format|
if @cart.save
- format.html { redirect_to @cart, notice: 'Cart was successfully created.' }
+ format.html { redirect_to store_index_url }
format.json { render :show, status: :created, location: @cart }
else
format.html { render :new }
diff --git a/app/controllers/store_controller.rb b/app/controllers/store_controller.rb
index 9a52290..5327e7f 100644
--- a/app/controllers/store_controller.rb
+++ b/app/controllers/store_controller.rb
@@ -1,4 +1,7 @@
class StoreController < ApplicationController
+ include CurrentCart
+ before_action :set_cart
+
def index
@products = Product.order(:title)
end
diff --git a/app/views/carts/_cart.html.erb b/app/views/carts/_cart.html.erb
new file mode 100644
index 0000000..ed3a0a2
--- /dev/null
+++ b/app/views/carts/_cart.html.erb
@@ -0,0 +1,13 @@
+
Your Cart
+
+
+ <%= render(cart.line_items) %>
+
+
+ | Total |
+ <%= number_to_currency(cart.total_price) %> |
+
+
+
+
+<%= button_to 'Empty Cart', cart, method: :delete, data: { confirm: 'Are you sure?'} %>
diff --git a/app/views/carts/show.html.erb b/app/views/carts/show.html.erb
index be99d19..5c68cf9 100644
--- a/app/views/carts/show.html.erb
+++ b/app/views/carts/show.html.erb
@@ -2,20 +2,4 @@
Your Cart
-
- <% @cart.line_items.each do |item| %>
-
- | <%= item.quantity %> × |
- <%= item.product.title %> |
- <%= number_to_currency(item.total_price) %> |
-
- <% end %>
-
-
- | Total |
- <%= number_to_currency(@cart.total_price) %> |
-
-
-
-
-<%= button_to 'Empty Cart', @cart, method: :delete, data: { confirm: 'Are you sure?'} %>
+<%= render @cart %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 2931bda..efdb61c 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -15,6 +15,12 @@
+
+ <% if @cart %>
+ <%= render @cart %>
+ <% end %>
+
+
- Home
- FAQ
diff --git a/app/views/line_items/_line_item.html.erb b/app/views/line_items/_line_item.html.erb
new file mode 100644
index 0000000..608b918
--- /dev/null
+++ b/app/views/line_items/_line_item.html.erb
@@ -0,0 +1,5 @@
+
+ | <%= line_item.quantity %> × |
+ <%= line_item.product.title %> |
+ <%= number_to_currency(line_item.total_price) %> |
+
diff --git a/test/controllers/carts_controller_test.rb b/test/controllers/carts_controller_test.rb
index 038894d..587ee91 100644
--- a/test/controllers/carts_controller_test.rb
+++ b/test/controllers/carts_controller_test.rb
@@ -20,7 +20,7 @@ class CartsControllerTest < ActionDispatch::IntegrationTest
post carts_url, params: { cart: { } }
end
- assert_redirected_to cart_url(Cart.last)
+ assert_redirected_to store_index_url
end
test "should show cart" do