From 45c9540eb5d3717ea3228aac5d0edcd6f31fb2fc Mon Sep 17 00:00:00 2001 From: samyou-softwire Date: Tue, 24 Mar 2026 16:28:32 +0000 Subject: [PATCH] CLDC-4340: Put all postcode locations at the end --- app/models/form/lettings/questions/location_id.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/form/lettings/questions/location_id.rb b/app/models/form/lettings/questions/location_id.rb index ee51688f1..acf395153 100644 --- a/app/models/form/lettings/questions/location_id.rb +++ b/app/models/form/lettings/questions/location_id.rb @@ -31,10 +31,14 @@ class Form::Lettings::Questions::LocationId < ::Form::Question scheme_location_ids = lettings_log.scheme.locations.visible.confirmed.pluck(:id) answer_options.select { |k, _v| scheme_location_ids.include?(k.to_i) } .sort_by { |_, v| - name_or_postcode = v["hint"] || v["value"] # name can be nil, postcode is never nil - name = name_or_postcode.match(/[a-zA-Z].*/).to_s - number = name_or_postcode.match(/\d+/).to_s.to_i - [name, number] + if v["hint"].present? + name = v["hint"] + name_text = name&.match(/[a-zA-Z].*/).to_s + number = name&.match(/\d+/).to_s.to_i + [0, name_text, number] + else + [1, v["value"]] + end }.to_h end