From 31890e753d2e1bbd167bb71b2bca34e19c316578 Mon Sep 17 00:00:00 2001 From: JG Date: Mon, 11 Jul 2022 13:56:12 +0100 Subject: [PATCH] WIP for validations --- app/controllers/schemes_controller.rb | 12 ++++++++++-- app/models/scheme.rb | 1 + config/locales/en.yml | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 9c5e4dcc5..967579fac 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -27,8 +27,9 @@ class SchemesController < ApplicationController def create @scheme = Scheme.new(scheme_params) if @scheme.save - render "schemes/primary_client_group" + redirect_to scheme_primary_client_group_path(@scheme) else + debugger @scheme.errors.add(:owning_organisation_id, message: @scheme.errors[:organisation]) @scheme.errors.delete(:owning_organisation) render :new, status: :unprocessable_entity @@ -51,7 +52,7 @@ class SchemesController < ApplicationController redirect_to next_page_path params[:scheme][:page] end else - render request.current_url, status: :unprocessable_entity + render current_template(request.referer), status: :unprocessable_entity end end @@ -89,6 +90,13 @@ private page == "confirm-secondary" && @scheme.has_other_client_group == "Yes" end + def current_template(page) + case + when page.include?("primary") + "schemes/primary_client_group" + end + end + def next_page_path(page) case page when "primary-client-group" diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 6fac3daae..26840b79e 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -7,6 +7,7 @@ class Scheme < ApplicationRecord validates_presence_of :service_name validates_presence_of :scheme_type validates_presence_of :registered_under_care_act + validates :primary_client_group, presence: true, on: :update scope :filter_by_id, ->(id) { where(id: (id.start_with?("S") ? id[1..] : id)) } scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") } diff --git a/config/locales/en.yml b/config/locales/en.yml index 16f87f198..d58e6736f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -53,6 +53,9 @@ en: blank: "Select the scheme’s type" registered_under_care_act: blank: "You must tell us if this scheme is registered under the Care Standards Act 2000" + primary_client_group: + blank: "Select what client group is this scheme intended for" + validations: organisation: