From 4eda2a5dbf24b59af5a703f73707a9aa33a858c5 Mon Sep 17 00:00:00 2001 From: JG Date: Tue, 28 Jun 2022 09:56:19 +0100 Subject: [PATCH] doing silly dance to get correct field highlighted on the error --- app/controllers/schemes_controller.rb | 2 ++ app/models/scheme.rb | 2 -- config/locales/en.yml | 5 +---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 7b2ae134d..afc923b71 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -34,6 +34,8 @@ class SchemesController < ApplicationController if @scheme.save render "schemes/primary_client_group" else + @scheme.errors.add(:organisation_id, message: @scheme.errors[:organisation]) + @scheme.errors.delete(:organisation) render :new, status: :unprocessable_entity end end diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 99b3b1e02..e2036c7ed 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -10,8 +10,6 @@ class Scheme < ApplicationRecord scope :search_by_postcode, ->(postcode) { joins(:locations).where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") } scope :search_by, ->(param) { search_by_postcode(param).or(search_by_service_name(param)).or(search_by_code(param)).distinct } - validates :organisation_id, presence: { message: I18n.t("validations.scheme.organisation_id_missing") } - SENSITIVE = { No: 0, Yes: 1, diff --git a/config/locales/en.yml b/config/locales/en.yml index 8ce37bf66..71fb99454 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -44,12 +44,9 @@ en: scheme: attributes: organisation: - required: "" + required: "Enter the organisation’s name" validations: - scheme: - organisation_id_missing: "Enter the organisation’s name" - organisation: name_missing: "Enter the organisation’s name" provider_type_missing: "Select the organisation’s type"