From f0e2d426c3c0a8c754adefb472b5feb0b0cb6a6c Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 12 Jul 2017 19:23:15 +0200 Subject: [PATCH] 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. --- .../spree/admin/line_items_controller_decorator.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/spree/admin/line_items_controller_decorator.rb b/app/controllers/spree/admin/line_items_controller_decorator.rb index 511ab1b4f6..ed81c8ae54 100644 --- a/app/controllers/spree/admin/line_items_controller_decorator.rb +++ b/app/controllers/spree/admin/line_items_controller_decorator.rb @@ -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