small medium large xlarge

Chef_pragsmall
27 Oct 2008, 14:18
Hendry Wijaya (2 posts)

I’ve been following the course of the chapter (2nd ed.) pretty smoothly until I am stuck with Iteration D2: Adding Ajax cart to depot (pg. 130-132). I have already get the code copied verbatim from the book (and from the given link) and but the error persists. The error says: When The “Add to Cart” button is pressed (which supposed to run the js code), the browser respond with message like: RJS error: TypeError: element is null. Element.update(“cart”, ….the cart template content….”); Strangely so, that after the error dialog was dismissed, I get the browser refreshed manually and the expected results (new item added to the cart) appear on the sidebar. I’ve tried to reload the index page, tried different browsers, same problem occurs.

Any help, hint, or pointers on the problem would be very much appreciated.

Chef_pragsmall
28 Oct 2008, 03:20
Hendry Wijaya (2 posts)

After strolling around the site for solutions, I found out that the post by Ben Ward (http://forums.pragprog.com/forums/66/topics/582) solves the problem.

“It turned out the RJS template was set to update a div in one of my views which had been labelled with a CLASS, rather than an ID. “

Quick solution: Try changing the class= to id= in _cart.html.erb.

I think further revision of the book is needed to stress the detail on AJAX Rails subtleties.

Thanks to Ben!

You must be logged in to comment