Permalink
Browse files

Added orders controller

  • Loading branch information...
rbarazi committed Apr 14, 2010
1 parent c4e6db4 commit e35b52b485da1a1285bab64519c4f09d51d562d5
@@ -2,7 +2,8 @@ class CartsController < ApplicationController
before_filter :authenticate_user!, :only => :checkout
def confirm
- order = current_cart.update_attributes(params[:order])
+ order = current_cart
+ order.update_attributes(params[:order])
clear_cart!
redirect_to order, :notice => "Your order is on the way!"
end
@@ -0,0 +1,11 @@
+class OrdersController < ApplicationController
+ before_filter :authenticate_user!
+
+ def index
+ @orders = current_user.orders
+ end
+
+ def show
+ @order = current_user.orders.find(params[:id])
+ end
+end
@@ -0,0 +1,2 @@
+module OrdersHelper
+end
@@ -0,0 +1,7 @@
+<ul id="orders">
+ <% @orders.each do |order| %>
+ <li>
+ <%= number_to_currency order.total %> -
+ </li>
+ <% end %>
+</ul>
@@ -0,0 +1,10 @@
+<ul id="cart">
+ <% @order.items.each do |item| %>
+ <li>
+ <%= item.name %> - <%= item.quantity %> x <%= number_to_currency item.price %> = <%= number_to_currency item.total %> -
+ </li>
+ <% end %>
+ <li class="total">
+ <%= number_to_currency @order.total %>
+ </li>
+</ul>
View
@@ -1,5 +1,6 @@
Pizzaria::Application.routes.draw do |map|
resources :products
+ resources :orders
resource :cart do
get :checkout
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class OrdersControllerTest < ActionController::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class OrdersHelperTest < ActionView::TestCase
+end

0 comments on commit e35b52b

Please sign in to comment.