Shopping Cart for production

Reading the Agile book there’s an excerpt that states:

‘‘Make the Cart class an Active Record object and store cart data in
the database. The session would then store the cart object’s id. When
a request comes in, we’d extract this id from the session and then
load the cart from the database.’’

This Cart class had the methods below. It initializes an @items array
which contains CartItem objects (which doesn’t extends from
ActiveRecord). My guess is that this CartItem class should also be
changed into an ActiveRecord object eventhough this point is not
mentioned on the book. Am I right making this assumption?

Thanks!

class Cart

def initialize
@items = []
end

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

end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs