| @@ -6,7 +6,7 @@ | |||||
| * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. | * 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 | * 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. | * 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. | * It is generally better to create a new file per style scope. | ||||
| * | * | ||||
| @@ -60,6 +60,25 @@ | |||||
| padding: 1em 2em; | padding: 1em 2em; | ||||
| background: #141; | 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 { | ul { | ||||
| padding: 0; | padding: 0; | ||||
| @@ -1,7 +1,7 @@ | |||||
| // Place all the styles related to the Carts controller here. | // Place all the styles related to the Carts controller here. | ||||
| // They will automatically be included in application.css. | // They will automatically be included in application.css. | ||||
| // You can use Sass (SCSS) here: http://sass-lang.com/ | // You can use Sass (SCSS) here: http://sass-lang.com/ | ||||
| .carts { | |||||
| .carts, #side #cart { | |||||
| .item_price, .total_line { | .item_price, .total_line { | ||||
| text-align: right; | text-align: right; | ||||
| } | } | ||||
| @@ -30,7 +30,7 @@ class CartsController < ApplicationController | |||||
| respond_to do |format| | respond_to do |format| | ||||
| if @cart.save | 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 } | format.json { render :show, status: :created, location: @cart } | ||||
| else | else | ||||
| format.html { render :new } | format.html { render :new } | ||||
| @@ -1,4 +1,7 @@ | |||||
| class StoreController < ApplicationController | class StoreController < ApplicationController | ||||
| include CurrentCart | |||||
| before_action :set_cart | |||||
| def index | def index | ||||
| @products = Product.order(:title) | @products = Product.order(:title) | ||||
| end | end | ||||
| @@ -0,0 +1,13 @@ | |||||
| <h2>Your Cart</h2> | |||||
| <table> | |||||
| <%= render(cart.line_items) %> | |||||
| <tr class="total_line"> | |||||
| <td colspan="2">Total</td> | |||||
| <td class="total_cell"><%= number_to_currency(cart.total_price) %></td> | |||||
| </tr> | |||||
| </table> | |||||
| <%= button_to 'Empty Cart', cart, method: :delete, data: { confirm: 'Are you sure?'} %> | |||||
| @@ -2,20 +2,4 @@ | |||||
| <h2>Your Cart</h2> | <h2>Your Cart</h2> | ||||
| <table> | |||||
| <% @cart.line_items.each do |item| %> | |||||
| <tr> | |||||
| <td><%= item.quantity %> ×</td> | |||||
| <td><%= item.product.title %></td> | |||||
| <td class="item_price"><%= number_to_currency(item.total_price) %></td> | |||||
| </tr> | |||||
| <% end %> | |||||
| <tr class="total_line"> | |||||
| <td colspan="2">Total</td> | |||||
| <td class="total_cell"><%= number_to_currency(@cart.total_price) %></td> | |||||
| </tr> | |||||
| </table> | |||||
| <%= button_to 'Empty Cart', @cart, method: :delete, data: { confirm: 'Are you sure?'} %> | |||||
| <%= render @cart %> | |||||
| @@ -15,6 +15,12 @@ | |||||
| </div> | </div> | ||||
| <div id="columns"> | <div id="columns"> | ||||
| <div id="side"> | <div id="side"> | ||||
| <div id="cart"> | |||||
| <% if @cart %> | |||||
| <%= render @cart %> | |||||
| <% end %> | |||||
| </div> | |||||
| <ul> | <ul> | ||||
| <li><a href="/">Home</a></li> | <li><a href="/">Home</a></li> | ||||
| <li><a href="/faq">FAQ</a></li> | <li><a href="/faq">FAQ</a></li> | ||||
| @@ -0,0 +1,5 @@ | |||||
| <tr> | |||||
| <td><%= line_item.quantity %> ×</td> | |||||
| <td><%= line_item.product.title %></td> | |||||
| <td class="item_price"><%= number_to_currency(line_item.total_price) %></td> | |||||
| </tr> | |||||
| @@ -20,7 +20,7 @@ class CartsControllerTest < ActionDispatch::IntegrationTest | |||||
| post carts_url, params: { cart: { } } | post carts_url, params: { cart: { } } | ||||
| end | end | ||||
| assert_redirected_to cart_url(Cart.last) | |||||
| assert_redirected_to store_index_url | |||||
| end | end | ||||
| test "should show cart" do | test "should show cart" do | ||||