Page 129 of Agile Web Dev on Rails (or pg141 of pdf!)

Hi - another question, sorry…

I’m trying to get the highlighting effect to work on the current_item.
The page refreshes fine, and then I get an error as the highlighting
code is fired:

page[:current_item].visual_effect :highlight,
:startcolor => “#88ff88”,
:endcolor => “#114411

The error is: RJS Error [object Error] (which is helpful!)

Followed by a pop up window containing the page code, the last line of
which is:
$(“current_item”).visualEffect(“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 invalid product #{params[:id]}”)
redirect_to_index(“Invalid product”)
else
@cart = find_cart
@current_item = @cart.add_product(@product)
end
end

Code in _cart_item.rhtml:
<% if cart_item == @current_item %>

<% else %> <% end %> <%= cart_item.quantity %>× <%= h(cart_item.title) %> <%= format_price(cart_item.price) %>

What is it that I can’t see!?

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