Rails Shopping Cart - not adding to current order

馋奶兔 提交于 2019-12-05 14:37:13

It looks like ProductsController#create is called twice, once with format html and once as json.

I think you're submitting some of your data via ajax but still doing a post request from the form. However your controller, in it's format.html response is redirecting before all of the javascript actions have completed.

Since you only save @order and set the session from OrderItemsController#create which is called by js after your initial ajax().success, it is incomplete when the redirect is received.

What I think happens on click:

  1. ajax post request AND regular form post
  2. ajax success -> submit #order_item_product_id form
  3. redirected by original form post response

I would suggest either redesigning the submit process to submit through regular form post or entirely through js. For example you could disable post from the form and change OrderItemsController#create to finally redirect (via js) render :js => "window.location.href = '/cart';"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!