# Ajax magic does not work - Book Agil Development with Rails

**URL:** <https://www.ruby-forum.com/t/ajax-magic-does-not-work-book-agil-development-with-rails/154452>\
**Category:** Rails\
**Created:** [November 29, 2008, 10:02pm UTC](https://www.ruby-forum.com/t/ajax-magic-does-not-work-book-agil-development-with-rails/154452 "2008-11-29T22:02:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![edipofederle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a88e4f/32.png) [@edipofederle](https://www.ruby-forum.com/u/edipofederle)\
**Post date:** [November 29, 2008, 10:02pm UTC](https://www.ruby-forum.com/t/ajax-magic-does-not-work-book-agil-development-with-rails/154452/1 "2008-11-29T22:02:43Z")

</div>

Ajax magic does not work - Book Agil Development with Rails( Edition 2)

I’m trying to run the part where the effect is implemented in  
application hightlight depot but is not working, I tried to download the  
codes on the site but it also does not work so someone step

Sorry english evil, I am learning:)

Codes

cart.rb  
`
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
`

store\_controller  
`
def add_to_cart
begin
product = Product.find(params[:id])
rescue ActiveRecord::RecordNotFound
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
`

Partial \_cart\_item.rhtml  
`
<% if cart_item == @current_item %>`

 \<% else %\> \<% end %\>

```
    <td><%= cart_item.quantity %>&times;</td>
    <td><%= h(cart_item.title) %> </td>
    <td class="item-price"><%= number_to_currency(cart_item.price)

```

%\>

add\_to\_cart.rjs

`
page.replace_html("cart", :partial => "cart", :object => @cart)
page[:current_item].visual_effect :highlight,
:startcolor =>
“#88ff88”,
:endcolor =>
“#114411”
`

Thaks

---

<div class="post-metadata">

**Author:** ![edipofederle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a88e4f/32.png) [@edipofederle](https://www.ruby-forum.com/u/edipofederle)\
**Post date:** [November 30, 2008, 1:37am UTC](https://www.ruby-forum.com/t/ajax-magic-does-not-work-book-agil-development-with-rails/154452/2 "2008-11-30T01:37:24Z")

</div>

On Nov 29, 9:02 pm, Edipofederle Edipofederle \<rails-mailing-  
removed\_email\_address@domain.invalid\> wrote:

> Ajax magic does not work - Book Agil Development with Rails( Edition 2)
> 
> I’m trying to run the part where the effect is implemented in  
> application hightlight depot but is not working, I tried to download the  
> codes on the site but it also does not work so someone step

In what way does it not work?

Fred
