From b2b7a9ea86313f5a6baf0011d3f1fbfd8447691e Mon Sep 17 00:00:00 2001 From: JG Date: Wed, 25 May 2022 15:28:24 +0100 Subject: [PATCH] postcode searching code --- app/models/case_log.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index a311eae40..aec585f50 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -54,7 +54,11 @@ class CaseLog < ApplicationRecord scope :search_by_id, ->(id) { where(id: id) } scope :search_by_tenancy_code, ->(code) { where(tenancy_code: code) } scope :search_by_propcode, ->(code) { where(propcode: code) } - scope :search_by, ->(param) { search_by_id(param.to_i).or(search_by_tenancy_code(param)).or(search_by_propcode(param)) } + scope :search_by_postcode, ->(code) { where(postcode_full: code) } + scope :search_by, ->(param) { search_by_id(param.to_i) + .or(search_by_tenancy_code(param)) + .or(search_by_propcode(param)) + .or(search_by_postcode(param.upcase.gsub(/\s+/, ""))) } AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze OPTIONAL_FIELDS = %w[first_time_property_let_as_social_housing tenant_code propcode].freeze