Fix getting HTML when deleting line item in admin

In the step 6 of the spree upgrade, when deleting an order's line item
from /admin we get an HTML response (the whole edit form) that gets
inserted into the flash error.

It's not 100% clear why we added a respond_to block for JSON but since
juery-rails sends ajax requests with application/javascript, */* in
the ACCEPTS request header, Rails falls back to the first specified respond_to
block, which is HTML. We don't hit the JSON block.

In order for this to work, this commit replaces the JSON respond_to
block with one for JS with the exact same behaviour; returning a 204.
This is also the format the spree controller action we duplicated originally
has besides HTML.
This commit is contained in:
Pau Perez
2017-07-12 19:23:15 +02:00
committed by Rob Harrington
parent 8c56bd23fc
commit f0e2d426c3

View File

@@ -2,8 +2,6 @@ Spree::Admin::LineItemsController.class_eval do
prepend_before_filter :load_order, except: :index
around_filter :apply_enterprise_fees_with_lock, only: :update
respond_to :json
# TODO make updating line items faster by creating a bulk update method
def index
@@ -52,7 +50,7 @@ Spree::Admin::LineItemsController.class_eval do
respond_to do |format|
format.html { render_order_form }
format.json { render nothing: true, status: 204 } # No Content
format.js { render nothing: true, status: 204 } # No Content
end
end