|
|
@ -5,22 +5,28 @@ class CaseLogValidator < ActiveModel::Validator |
|
|
|
|
|
|
|
|
|
|
|
def validate_tenant_code(record) |
|
|
|
def validate_tenant_code(record) |
|
|
|
if record.tenant_code.blank? |
|
|
|
if record.tenant_code.blank? |
|
|
|
record.errors.add :tenant_code, "Tenant code can't be blank" |
|
|
|
# record.errors.add :tenant_code, "Tenant code can't be blank" |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def validate_tenant_age(record) |
|
|
|
def validate_tenant_age(record) |
|
|
|
if record.tenant_age.blank? |
|
|
|
# if record.tenant_age.blank? |
|
|
|
record.errors.add :tenant_age, "Tenant age can't be blank" |
|
|
|
# record.errors.add :tenant_age, "Tenant age can't be blank" |
|
|
|
elsif !/^[1-9][0-9]?$|^100$/.match?(record.tenant_age.to_s) |
|
|
|
# elsif !/^[1-9][0-9]?$|^100$/.match?(record.tenant_age.to_s) |
|
|
|
|
|
|
|
# record.errors.add :tenant_age, "Tenant age must be between 0 and 100" |
|
|
|
|
|
|
|
# end |
|
|
|
|
|
|
|
if record.tenant_age && !/^[1-9][0-9]?$|^100$/.match?(record.tenant_age.to_s) |
|
|
|
record.errors.add :tenant_age, "Tenant age must be between 0 and 100" |
|
|
|
record.errors.add :tenant_age, "Tenant age must be between 0 and 100" |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def validate(record) |
|
|
|
def validate(record) |
|
|
|
question_to_validate = options[:previous_page] |
|
|
|
question_to_validate = options[:previous_page] |
|
|
|
if respond_to?("validate_#{question_to_validate}") |
|
|
|
if question_to_validate && respond_to?("validate_#{question_to_validate}") |
|
|
|
public_send("validate_#{question_to_validate}", record) |
|
|
|
public_send("validate_#{question_to_validate}", record) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
validation_methods = public_methods(false) - [__callee__] |
|
|
|
|
|
|
|
validation_methods.each { |meth| public_send(meth, record) } |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|