diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index b80d969a0..fa2c88a3f 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -210,12 +210,22 @@ class LocationsController < ApplicationController end def new_reactivation - @location_deactivation_period = @location.location_deactivation_periods.deactivations_without_reactivation.first + open_deactivations = @location.location_deactivation_periods.deactivations_without_reactivation + if open_deactivations.blank? + render_not_found and return + end + + @location_deactivation_period = open_deactivations.first render "toggle_active", locals: { action: "reactivate" } end def reactivate - @location_deactivation_period = @location.location_deactivation_periods.deactivations_without_reactivation.first + open_deactivations = @location.location_deactivation_periods.deactivations_without_reactivation + if open_deactivations.blank? + render_not_found and return + end + + @location_deactivation_period = open_deactivations.first @location_deactivation_period.reactivation_date = toggle_date("reactivation_date") @location_deactivation_period.reactivation_date_type = params[:location_deactivation_period][:reactivation_date_type] diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 27504e9de..4b018ee34 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -88,13 +88,22 @@ class SchemesController < ApplicationController end def new_reactivation - @scheme_deactivation_period = @scheme.scheme_deactivation_periods.deactivations_without_reactivation.first + open_deactivations = @scheme.scheme_deactivation_periods&.deactivations_without_reactivation + if open_deactivations.blank? + render_not_found and return + end + + @scheme_deactivation_period = open_deactivations.first render "toggle_active", locals: { action: "reactivate" } end def reactivate - @scheme_deactivation_period = @scheme.scheme_deactivation_periods.deactivations_without_reactivation.first + open_deactivations = @scheme.scheme_deactivation_periods&.deactivations_without_reactivation + if open_deactivations.blank? + render_not_found and return + end + @scheme_deactivation_period = open_deactivations.first @scheme_deactivation_period.reactivation_date = toggle_date("reactivation_date") @scheme_deactivation_period.reactivation_date_type = params[:scheme_deactivation_period][:reactivation_date_type]