Browse Source

WIP for validations

juris_katrina_test
JG 3 years ago
parent
commit
31890e753d
  1. 12
      app/controllers/schemes_controller.rb
  2. 1
      app/models/scheme.rb
  3. 3
      config/locales/en.yml

12
app/controllers/schemes_controller.rb

@ -27,8 +27,9 @@ class SchemesController < ApplicationController
def create def create
@scheme = Scheme.new(scheme_params) @scheme = Scheme.new(scheme_params)
if @scheme.save if @scheme.save
render "schemes/primary_client_group" redirect_to scheme_primary_client_group_path(@scheme)
else else
debugger
@scheme.errors.add(:owning_organisation_id, message: @scheme.errors[:organisation]) @scheme.errors.add(:owning_organisation_id, message: @scheme.errors[:organisation])
@scheme.errors.delete(:owning_organisation) @scheme.errors.delete(:owning_organisation)
render :new, status: :unprocessable_entity render :new, status: :unprocessable_entity
@ -51,7 +52,7 @@ class SchemesController < ApplicationController
redirect_to next_page_path params[:scheme][:page] redirect_to next_page_path params[:scheme][:page]
end end
else else
render request.current_url, status: :unprocessable_entity render current_template(request.referer), status: :unprocessable_entity
end end
end end
@ -89,6 +90,13 @@ private
page == "confirm-secondary" && @scheme.has_other_client_group == "Yes" page == "confirm-secondary" && @scheme.has_other_client_group == "Yes"
end end
def current_template(page)
case
when page.include?("primary")
"schemes/primary_client_group"
end
end
def next_page_path(page) def next_page_path(page)
case page case page
when "primary-client-group" when "primary-client-group"

1
app/models/scheme.rb

@ -7,6 +7,7 @@ class Scheme < ApplicationRecord
validates_presence_of :service_name validates_presence_of :service_name
validates_presence_of :scheme_type validates_presence_of :scheme_type
validates_presence_of :registered_under_care_act 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 :filter_by_id, ->(id) { where(id: (id.start_with?("S") ? id[1..] : id)) }
scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") } scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") }

3
config/locales/en.yml

@ -53,6 +53,9 @@ en:
blank: "Select the scheme’s type" blank: "Select the scheme’s type"
registered_under_care_act: registered_under_care_act:
blank: "You must tell us if this scheme is registered under the Care Standards Act 2000" 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: validations:
organisation: organisation:

Loading…
Cancel
Save