|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
class CaseLogValidator < ActiveModel::Validator |
|
|
|
|
# Validations methods need to be called 'validate_<page_name>' to run on model save |
|
|
|
|
# or 'validate_' to run on submit as well |
|
|
|
|
# Validations methods need to be called 'validate_' to run on model save |
|
|
|
|
# or form page submission |
|
|
|
|
include HouseholdValidations |
|
|
|
|
include PropertyValidations |
|
|
|
|
include FinancialValidations |
|
|
|
@ -8,16 +8,8 @@ class CaseLogValidator < ActiveModel::Validator
|
|
|
|
|
include DateValidations |
|
|
|
|
|
|
|
|
|
def validate(record) |
|
|
|
|
# If we've come from the form UI we only want to validate the specific fields |
|
|
|
|
# that have just been submitted. If we're submitting a log via API or Bulk Upload |
|
|
|
|
# we want to validate all data fields. |
|
|
|
|
page_to_validate = record.page_id |
|
|
|
|
if page_to_validate |
|
|
|
|
public_send("validate_#{page_to_validate}", record) if respond_to?("validate_#{page_to_validate}") |
|
|
|
|
else |
|
|
|
|
validation_methods = public_methods.select { |method| method.starts_with?("validate_") } |
|
|
|
|
validation_methods.each { |meth| public_send(meth, record) } |
|
|
|
|
end |
|
|
|
|
validation_methods = public_methods.select { |method| method.starts_with?("validate_") } |
|
|
|
|
validation_methods.each { |meth| public_send(meth, record) } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
private |
|
|
|
@ -44,8 +36,6 @@ class CaseLog < ApplicationRecord
|
|
|
|
|
validates_with CaseLogValidator |
|
|
|
|
before_save :update_status! |
|
|
|
|
|
|
|
|
|
attr_accessor :page_id |
|
|
|
|
|
|
|
|
|
enum status: { "not_started" => 0, "in_progress" => 1, "completed" => 2 } |
|
|
|
|
|
|
|
|
|
enum ethnic: DbEnums.ethnic |
|
|
|
|