From 53fb77eb2336665ee3f93f18917c99ea4c97e5b0 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Thu, 23 May 2024 14:30:28 +0500 Subject: [PATCH] 12398: add destroy action with turbo stream --- app/controllers/admin/products_v3_controller.rb | 8 ++++++++ app/views/admin/products_v3/destroy.turbo_stream.haml | 1 + config/routes/admin.rb | 2 ++ 3 files changed, 11 insertions(+) create mode 100644 app/views/admin/products_v3/destroy.turbo_stream.haml diff --git a/app/controllers/admin/products_v3_controller.rb b/app/controllers/admin/products_v3_controller.rb index 77098ee7bb..90505150fd 100644 --- a/app/controllers/admin/products_v3_controller.rb +++ b/app/controllers/admin/products_v3_controller.rb @@ -31,6 +31,14 @@ module Admin end end + # will update this in further commits + def destroy + @product = Spree::Product.find(params[:id]) + respond_with do |format| + format.turbo_stream + end + end + def index_url(params) "/admin/products?#{params.to_query}" # todo: fix routing so this can be automaticly generated end diff --git a/app/views/admin/products_v3/destroy.turbo_stream.haml b/app/views/admin/products_v3/destroy.turbo_stream.haml new file mode 100644 index 0000000000..8f19c2fdfe --- /dev/null +++ b/app/views/admin/products_v3/destroy.turbo_stream.haml @@ -0,0 +1 @@ += turbo_stream.remove dom_id(@product) diff --git a/config/routes/admin.rb b/config/routes/admin.rb index c82fb18315..3d4665eea2 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -75,6 +75,8 @@ Openfoodnetwork::Application.routes.draw do # This might be easier to arrange once we rename the controller to plain old "products" post '/products/bulk_update', to: 'products_v3#bulk_update' get '/products', to: 'products_v3#index' + # we already have DELETE admin/products/:id here + delete 'products_v3/:id', to: 'products_v3#destroy', as: 'product_destroy' end resources :variant_overrides do