Displaying 3 results from an estimated 3 matches for "existing_product".
2006 Jul 24
1
Newbie error: undefined local variable or method
...troller:
def add_to_cart
@cart = find_cart
@product = Product.find(params[:id])
@cart.add_product(@product)
end
The add_product method is in the Cart model:
class Cart
include Reloadable
attr_reader :items
def initialize
@items = []
end
def add_product(product)
existing_product = @items.find {|item| item.product == product}
if existing_product
existing_product.increment_quantity
else
@items << CartItem.new(product)
end
end
end
The cart_item.quantity and cart_item.title come from the CartItem model:
class CartItem
include Reloadable
attr_reader :pr...
2006 Aug 04
6
Errors ... errors and errors.
...sesssion add one
session[:cart] = Cart.new #add a new one
end
session[:cart] #return existing or new cart
end
end
[CODE]
Also here is the cart.rb
[CODE]
class Cart
include Reloadable
attr_reader :items
def initialize
@items = []
end
def add_product(product)
existing_product = @items.find {|item| item.product == product}
if existing_product
existing_product.increment_quantity
else
@items << Cart.new(product)
end
end
end
[CODE]
And here is the cart_item.rb
[CODE]
class CartItem
include Reloadable
attr_reader :product, :quantity
d...
2006 Jun 08
19
Agile Web Dev (book) question: errors
This is kind of frustrating (but no doubt helpful in the long run) that
after following along and coding , and d/l the code the same error is
appearing.
For those who are familiar with the depot app, I''ve run into a problem after
fixing the cart to reflect quanitites. I worked through the intended error
messages but now have this appearing:
SyntaxError in StoreController#add_to_cart