Browse Source

code to get controller render errors when required param is missing

pull/671/head
JG 3 years ago
parent
commit
209fd7f225
  1. 6
      app/controllers/schemes_controller.rb
  2. 2
      app/models/scheme.rb
  3. 3
      config/locales/en.yml

6
app/controllers/schemes_controller.rb

@ -30,8 +30,12 @@ class SchemesController < ApplicationController
end
def create
@scheme = Scheme.create!(scheme_params)
@scheme = Scheme.new(scheme_params)
if @scheme.save
render "schemes/primary_client_group"
else
render :new, status: :unprocessable_entity
end
end
def update

2
app/models/scheme.rb

@ -5,6 +5,8 @@ class Scheme < ApplicationRecord
has_many :locations
has_many :case_logs
validates :organisation_id, presence: { message: I18n.t("validations.scheme.id_missing") }
scope :search_by_code, ->(code) { where("code ILIKE ?", "%#{code}%") }
scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") }
scope :search_by_postcode, ->(postcode) { joins(:locations).where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") }

3
config/locales/en.yml

@ -39,6 +39,9 @@ en:
reset_password: "Reset your password"
validations:
scheme:
id_missing: "Enter the organisation’s name"
organisation:
name_missing: "Enter the organisation’s name"
provider_type_missing: "Select the organisation’s type"

Loading…
Cancel
Save