03 Jan 2014, 20:13
Generic-user-small

Mike Bonar (7 posts)

Hi folks,

Just finished Chapter 11, and the only weirdness I have is that click-able images add two products to the cart (product added twice). Any hints on where to look?

Mike

03 Jan 2014, 20:30
Generic-user-small

Mike Bonar (7 posts)

Oh, and the yellow blind affect doesn’t appear. However, this is common with table driven solutions. Need to somehow delay the ajax response. But, likely not related to the above issue. :)

04 Jan 2014, 17:21
Generic-user-small

Scott Fleck (3 posts)

I’m having the same problem with the double submit (although the blind action is OK for me). I’ll add some more detail on what I’ve observed.

The “Add to cart” button always works fine. One click adds one item to the cart. Clicking the image with the CoffeeScript magic, however, adds 2 items.

Also note: if I change the button_to function to “:remote false” then both links (the button and the image) only add 1 item to the cart each time.

      <div class="entry">
        <%= image_tag(product.image_url) %>
        <h3><%= product.title %></h3>
        <%= sanitize(product.description) %>
        <div class="price_line">
          <span class="price"><%= number_to_currency(product.price) %></span>
          <%= button_to 'Add to Cart', line_items_path(product_id: product),
            remote: true %>
        </div>
      </div>

In the log, clicking the image shows the action being called twice with no errors. This entry appears twice in a row with nothing between the 2 entries:

Started POST "/line_items?product_id=4" for 127.0.0.1 at 2014-01-04 10:04:33 -0500
Processing by LineItemsController#create as JS
  Parameters: {"authenticity_token"=>...
...
...
  Rendered line_items/_line_item.html.erb (2.4ms)
  Rendered carts/_cart.html.erb (3.9ms)
  Rendered line_items/create.js.erb (4.5ms)
Completed 200 OK in 16ms (Views: 5.3ms | ActiveRecord: 7.0ms)

Last note: I believe I was OK with the self-edited code (ie. building the Depot app by following the book). I had to restart with the code from the depot_o source and then I noticed the problem.

14 Jan 2014, 09:48
Generic-user-small

Anuj Middha (1 post)

Bump thread. Facing the same issue. I am writing the code by following the book.

23 Jan 2014, 16:34
Generic-user-small

Charles Watson (1 post)

After searching for a couple hours, I found the problem in the last place I thought to look… the book’s errata section

instead of

$(document).on "ready page:change", ->

it should be

$(document).on "ready, page:change", ->

with a comma after ‘ready’

its interesting how such a small mistake can produce those drastic results.

-Charles

07 Feb 2014, 19:17
Generic-user-small

Scott Fleck (3 posts)

Doh! Thanks Charles. That code change in the errata worked for me.

For those looking at this thread, the file that needs to change is:

store.js.coffee

31 Mar 2014, 00:58
Generic-user-small

Antonio Vera (2 posts)

Thanks a lot Charles!!!

BTW, in addition to the duplicated addition, in the browser’s console I saw a never ending flow of errors, reaching the thousands.

Now, everything is solved.

  You must be logged in to comment