11175
(-- --)
July 10, 2008, 9:51pm
1
NameError in StoreController#add_to_cart
uninitialized constant StoreController::Cart
This is the controller:
class StoreController < ApplicationController
def index
@products = Product.find_products_for_sale
end
def add_to_cart
@cart = find_cart
product = Product.find(params[:id])
@cart.add_product (product)
end
private
def find_cart
session[:cart] ||= Cart.new
end
end
Amd this is the model
class Cart
attr_reader :items
def initialize
@items =
end
def add_product(product)
@items << product
end
end
Thanks for the help
Hardbap
(Hardbap)
July 10, 2008, 10:07pm
2
NameError in StoreController#add_to_cart
uninitialized constant StoreController::Cart
This is the controller:
class StoreController < ApplicationController
def index
@products = Product.find_products_for_sale
end
def add_to_cart
@cart = find_cart
product = Product.find(params[:id])
@cart.add_product (product)
end
private
def find_cart
session[:cart] ||= Cart.new
end
end
Amd this is the model
class Cart
class Cart < ActiveRecord::Base
Did you just miss < ActiveRecord::Base when writing the email?
Best.
Mike
shenry
(shenry)
July 11, 2008, 5:40pm
4
Can you add items to the cart in the console?
This is wild speculation, I've never made an app with a cart, but
seems like you might need a has_many :items, :class_name => 'products'
in the Cart model?
CKomiya
(CKomiya)
October 30, 2009, 2:04am
5
maybe your file name is Cart.rb instead of cart.rb
Marnen Laibow-Koser-2 wrote: