From 3cec0847df00177bc1adaf0187c6ad4e07fde41a Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Sun, 27 Oct 2019 20:05:57 +0100 Subject: [PATCH] Quantity#destroy changed to AJAX --- app/controllers/quantities_controller.rb | 3 ++- app/views/quantities/_list.html.erb | 4 +++- app/views/quantities/toggle.js.erb | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/quantities_controller.rb b/app/controllers/quantities_controller.rb index 953a43e..34cfe3f 100644 --- a/app/controllers/quantities_controller.rb +++ b/app/controllers/quantities_controller.rb @@ -23,7 +23,8 @@ class QuantitiesController < ApplicationController if @quantity.destroy flash[:notice] = 'Deleted quantity' end - redirect_to project_quantities_url(@project) + @quantities = @project.quantities + render :toggle end def toggle diff --git a/app/views/quantities/_list.html.erb b/app/views/quantities/_list.html.erb index 7cb0ea8..2a1bb3f 100644 --- a/app/views/quantities/_list.html.erb +++ b/app/views/quantities/_list.html.erb @@ -76,7 +76,9 @@ <%= q.domain %> <%= q.description %> - <%= delete_link quantity_path(q), data: {} %> + + <%= delete_link quantity_path(q), {remote: true, data: {}} %> + <% end %> diff --git a/app/views/quantities/toggle.js.erb b/app/views/quantities/toggle.js.erb index 6501902..eb6067e 100644 --- a/app/views/quantities/toggle.js.erb +++ b/app/views/quantities/toggle.js.erb @@ -1 +1,3 @@ +$('div[id^=flash_]').remove(); +$('#content').prepend('<%= escape_javascript(render_flash_messages) %>'); $('#quantities').html('<%= escape_javascript(render :partial => 'quantities/list') %>');