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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---