From 72691077e8bbec9f4fbbf4f949ba418a9b4b30db Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Mon, 27 Mar 2023 12:28:45 +0100 Subject: [PATCH] refactor: move location helper methods to helpers --- app/controllers/locations_controller.rb | 4 +--- app/helpers/locations_helper.rb | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 8f41a0644..1653a0ff5 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -134,9 +134,7 @@ class LocationsController < ApplicationController def check_answers; end def confirm - if @location.confirmed - flash[:notice] = "#{@location.postcode} #{@location.startdate.blank? || @location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme" - end + flash[:notice] = helpers.location_creation_success_notice(@location) redirect_to scheme_locations_path(@scheme) end diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb index 5c51fc88c..92e12f074 100644 --- a/app/helpers/locations_helper.rb +++ b/app/helpers/locations_helper.rb @@ -78,6 +78,12 @@ module LocationsHelper return govuk_button_link_to "Reactivate this location", scheme_location_new_reactivation_path(location.scheme, location) if location.deactivated? end + def location_creation_success_notice(location) + if location.confirmed + "#{location.postcode} #{location.startdate.blank? || location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme" + end + end + private ActivePeriod = Struct.new(:from, :to)