Displaying 6 results from an estimated 6 matches for "increment_quantity".
2006 Jul 24
1
Newbie error: undefined local variable or method
....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 :product, :quantity
def initialize(product)
@product = product
@quantity = 1
end
def increment_quant...
2006 Aug 04
6
Errors ... errors and errors.
...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
def initialize(product)
@product = product
@quantity = 1
end
def increment_quantity
@quantity +=...
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
2006 Jul 18
15
Agile Web Developement with Rails
I recently got a copy of the second addition in PDF
and got stuck on the Ajax portion using highlighting
page 128. While trying to make my cart flash I got an
RJS error when I click add to cart. I have gone back
and made sure my code matched what was in the book but
no help. I sent Dave an email and he rec''d this list.
Anybody got any good links for troubleshooting Ajax or
maybe have see
2006 Jul 03
0
Page 129 of Agile Web Dev on Rails (or pg141 of pdf!)
...isualEffect("highlight", {"startcolor":"#88ff88",
"endcolor":"#114411"});
Code in cart.rb:
# add a product to the cart
def add_product(product)
current_item = @items.find {|item| item.product == product}
if current_item
current_item.increment_quantity
else
current_item = CartItem.new(product)
@items << current_item
end
current_item
end
Code in storecontroller.rb:
# add a product to the cart
def add_to_cart
begin
@product = Product.find(params[:id])
rescue
logger.error("Attempt to access...
2007 Sep 29
8
Inheritance problem in model
Hello,
I''ve got a problem with the inheritance as soon as I try to use it in a
model.
I''ve got plenty of items which can share a lot of code, so I created a
class "Item", which inherits from ActiveRecord::Base, but because it''s
not a "real item" but an interface, I set it abstract (writing
abstract_class? method).
Then I have all the differents