30 Jul 2012, 10:09
Generic-user-small

Abhishek Gutgutia (1 post)

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?

04 Aug 2012, 17:23
Generic-user-small

Jason Hagglund (4 posts)

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.

19 Sep 2012, 05:55
Img_1861_pragsmall

Cloud Chen (1 post)

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)

UPDATE: This problem seem caused by the number of jQuery libraries we included in our app. I just check my @/app/assets/javascript/application.js@ file and found that the “@// require jquery@” & “@// require jquery_ujs@”. Remove one of them then I got the “Add to cart” function work! Try it!

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!

28 Dec 2012, 16:00
Generic-user-small

Filip Abramowicz (1 post)

I was seeing exactly the same issue and after your post I found out that when trying to solve some other problems I’ve uncommented the line with @<%= javascript_include_tag “application” %>@ in application.html.erb. So after this there were two same lines and the libriaries must have been included twice.

After commenting the line again everything works fine.

05 Jan 2013, 14:40
Generic-user-small

Paul M (2 posts)

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:

http://stackoverflow.com/questions/7493068/upgrading-to-ruby-on-rails-3-1-the-jquery-ujs-js-file-should-be-deleted

End UPDATE

05 Jan 2013, 14:24
Generic-user-small

Paul M (2 posts)

Oh and as a - related - aside, the page counter goes up by 2 on every refresh.

  You must be logged in to comment