Browse Source

Iteration F1.

master
Nils Dittberner 9 years ago
parent
commit
93f41d7fa9
9 changed files with 51 additions and 21 deletions
  1. +20
    -1
      app/assets/stylesheets/application.scss
  2. +1
    -1
      app/assets/stylesheets/carts.scss
  3. +1
    -1
      app/controllers/carts_controller.rb
  4. +3
    -0
      app/controllers/store_controller.rb
  5. +13
    -0
      app/views/carts/_cart.html.erb
  6. +1
    -17
      app/views/carts/show.html.erb
  7. +6
    -0
      app/views/layouts/application.html.erb
  8. +5
    -0
      app/views/line_items/_line_item.html.erb
  9. +1
    -1
      test/controllers/carts_controller_test.rb

+ 20
- 1
app/assets/stylesheets/application.scss View File

@@ -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;



+ 1
- 1
app/assets/stylesheets/carts.scss View File

@@ -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;
}


+ 1
- 1
app/controllers/carts_controller.rb View File

@@ -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 }


+ 3
- 0
app/controllers/store_controller.rb View File

@@ -1,4 +1,7 @@
class StoreController < ApplicationController
include CurrentCart
before_action :set_cart
def index
@products = Product.order(:title)
end


+ 13
- 0
app/views/carts/_cart.html.erb View File

@@ -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?'} %>

+ 1
- 17
app/views/carts/show.html.erb View File

@@ -2,20 +2,4 @@

<h2>Your Cart</h2>

<table>
<% @cart.line_items.each do |item| %>
<tr>
<td><%= item.quantity %> &times;</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 %>

+ 6
- 0
app/views/layouts/application.html.erb View File

@@ -15,6 +15,12 @@
</div>
<div id="columns">
<div id="side">
<div id="cart">
<% if @cart %>
<%= render @cart %>
<% end %>
</div>

<ul>
<li><a href="/">Home</a></li>
<li><a href="/faq">FAQ</a></li>


+ 5
- 0
app/views/line_items/_line_item.html.erb View File

@@ -0,0 +1,5 @@
<tr>
<td><%= line_item.quantity %> &times;</td>
<td><%= line_item.product.title %></td>
<td class="item_price"><%= number_to_currency(line_item.total_price) %></td>
</tr>

+ 1
- 1
test/controllers/carts_controller_test.rb View File

@@ -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


Loading…
Cancel
Save