From 54a40fe79c672f22697d3227c522c24d7308e4b0 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 7 Dec 2019 14:51:17 +0100 Subject: [PATCH] Handle validation messages when saving new fees --- .../admin/enterprise_fees_controller.rb | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/enterprise_fees_controller.rb b/app/controllers/admin/enterprise_fees_controller.rb index 1b1f3cee80..f462569c4b 100644 --- a/app/controllers/admin/enterprise_fees_controller.rb +++ b/app/controllers/admin/enterprise_fees_controller.rb @@ -28,15 +28,12 @@ module Admin def bulk_update @enterprise_fee_set = EnterpriseFeeSet.new(params[:enterprise_fee_set]) - if @enterprise_fee_set.save - redirect_path = main_app.admin_enterprise_fees_path - if params.key? :enterprise_id - redirect_path = main_app.admin_enterprise_fees_path(enterprise_id: params[:enterprise_id]) - end - redirect_to redirect_path, notice: I18n.t(:enterprise_fees_update_notice) + if @enterprise_fee_set.save + redirect_to redirect_path, notice: I18n.t(:enterprise_fees_update_notice) else - render :index + redirect_to redirect_path, + flash: { error: @enterprise_fee_set.errors.full_messages.to_sentence } end end @@ -73,5 +70,13 @@ module Admin def current_enterprise Enterprise.find params[:enterprise_id] if params.key? :enterprise_id end + + def redirect_path + if params.key? :enterprise_id + return main_app.admin_enterprise_fees_path(enterprise_id: params[:enterprise_id]) + end + + main_app.admin_enterprise_fees_path + end end end