From 111cb81d08d86bb2628ec1720a7b6eaa13793db2 Mon Sep 17 00:00:00 2001 From: zmagod Date: Thu, 1 Sep 2016 13:38:09 +0200 Subject: [PATCH 1/2] clear tables from report [fixes SCI-247] again --- app/controllers/steps_controller.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/controllers/steps_controller.rb b/app/controllers/steps_controller.rb index e66260729..a098d0515 100644 --- a/app/controllers/steps_controller.rb +++ b/app/controllers/steps_controller.rb @@ -511,10 +511,21 @@ class StepsController < ApplicationController # In case of step model you can delete checkboxes, assets or tables. def destroy_attributes(params) update_params = {} + delete_step_tables(params) extract_destroy_params(params, update_params) @step.update_attributes(update_params) unless update_params.empty? end + # Delete the step table + def delete_step_tables(params) + return unless params[:tables_attributes].present? + params[:tables_attributes].each do |table| + next unless table.second['_destroy'] != 1 + table_to_destroy = Table.find_by(id: table.second['id']) + table_to_destroy.report_elements.destroy_all + end + end + # Checks if hash contains destroy parameter '_destroy' and returns # boolean value. def has_destroy_params(params) From 4afaa50ce0c814292017d836a32a3fba939883b6 Mon Sep 17 00:00:00 2001 From: zmagod Date: Thu, 1 Sep 2016 13:49:12 +0200 Subject: [PATCH 2/2] fixed multiple tables check --- app/controllers/steps_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/steps_controller.rb b/app/controllers/steps_controller.rb index a098d0515..1d06edc96 100644 --- a/app/controllers/steps_controller.rb +++ b/app/controllers/steps_controller.rb @@ -520,7 +520,7 @@ class StepsController < ApplicationController def delete_step_tables(params) return unless params[:tables_attributes].present? params[:tables_attributes].each do |table| - next unless table.second['_destroy'] != 1 + next unless table.second['_destroy'] table_to_destroy = Table.find_by(id: table.second['id']) table_to_destroy.report_elements.destroy_all end