I am trying to work through the Ajax example (iteration F2) and everything is working fine except that when I click “Add to Cart”, it adds 2 items to the cart and not 1. If I turn off Ajax (:remote => false), the problem disappears. Any help?
I am seeing this issue as well. However, for me it is only double-adding on the very first click on Add to Cart. Subsequent additions to the cart are adding only one item as expected.
I have the same issue as Abhishek does. Check the log of rails server, it given 2 POST request to rails server (do processing by LineItemsController#create)
PS: I am quite new to ruby on rails, so don’t know to much about the difference between these two jQuery files. Could anyone help to explain for us? Thanks!
After commenting the line again everything works fine.
Hrm, that line isn’t commented. I commented it manually, and obviously then this breaks the JS. Uncommenting again adds two items.
I must say, I am finding regular small issues when following this book, that I either have to figure out myself, or go the Teh Intraweb to find out, as the example code is buggy. It’s costing me a lot of time :o(
UPDATE: @ Cloud Chen Seems jQuery_ujs is just adding nice RoR stuff into jQuery. If you remove (jQuery) from the bottom of the file, you no longer have the errors, but I’m assuming it’ll break something else, somewhere.
The below link didn’t help me at all as it didn’t seem relevant to my version, but may help you:
Oh and as a - related - aside, the page counter goes up by 2 on every refresh.