Permalink
Browse files

Created a Cart Model

  • Loading branch information...
1 parent 654573f commit 1e1a22589134fcbb57d29f47832bf75d607ae444 @florida committed Nov 16, 2012
@@ -3,4 +3,22 @@ def index
@products = Product.available_items
end
+ def add_to_cart
+ product = Product.find(params[:id])
+ @cart = get_cart
+ @cart.add_line_item(product)
+ #display the cart
+ end
+
+ def show_cart
+ @cart = get_cart
+ @items = @cart.items
+ end
+
+
+private
+
+ def get_cart
+ session[:cart] ||= Cart.new
+ end
end
View
@@ -0,0 +1,3 @@
+class Cart < ActiveRecord::Base
+ # attr_accessible :title, :body
+end
@@ -7,5 +7,5 @@
<span class="label">Price</span>
<span class="value"><%= product.price %></span>
</section>
- <footer><%= link_to 'Buy Now', '#' %></footer>
+ <footer><%= link_to 'Buy Now', :action => 'add_to_cart', :id => product %></footer>
</section>
@@ -0,0 +1,5 @@
+<section class="product_show">
+ <section class="product_image">
+ <%= image_tag %>
+ </section>
+</section>
View
@@ -1,5 +1,5 @@
Elmorfstore::Application.routes.draw do
- get "store/index"
+ match 'store' => 'store#index', :as => 'store', :via => :get
# get "store/index"
@@ -0,0 +1,8 @@
+class CreateCarts < ActiveRecord::Migration
+ def change
+ create_table :carts do |t|
+
+ t.timestamps
+ end
+ end
+end
View
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
View
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class CartTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

0 comments on commit 1e1a225

Please sign in to comment.