Working through Agile Web Development with Rails – Part 3
Iteration D3: Highlight Changes
This error had me stumped for a while, although it did force me to read through and really understand how the code was working. Something I have found a little difficult in Ruby is the debugging. Coming from a .Net background we have been spoilt with the debugging capabilities of Visual Studio, sometimes to the determent of knowing what is actually going on.
The error occurs when added a new product to the Cart. You get two dialog boxes the first gives “RJS Error: [Object Error]” followed by “Element.update(”cart”, …” this error showed the correctly rendered HTML that was inserted into the cart after clicking ok.


The “Highlight” effect was also missing from the cart item. Reason the <tr> tag for the cart item did not have the id <tr id=”current_item”> However the logic here look sound as the highlight did work for adding additional items of existing products. The problem must therefore be in the Cart.rb file which handles the add_product method.
The line @items << CartItem.new(product) should read @items << current_item = CartItem.new(product)
This assigns the newly created cart item to the current_item variable which is in turn added to the cart items.
