Matthew Phelan
3 years ago
3 changed files with 22 additions and 4 deletions
@ -1,3 +1,19 @@ |
|||||||
|
class CaseLogValidator < ActiveModel::Validator |
||||||
|
def validate_tenant_age(record) |
||||||
|
if record.tenant_age < 0 |
||||||
|
record.errors.add :base, "Age needs to be above 0" |
||||||
|
elsif record.tenant_age > 120 |
||||||
|
record.errors.add :base, "Age needs to be below 120" |
||||||
|
end |
||||||
|
binding.pry |
||||||
|
end |
||||||
|
|
||||||
|
def validate(record) |
||||||
|
validate_tenant_age(record) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
class CaseLog < ApplicationRecord |
class CaseLog < ApplicationRecord |
||||||
enum status: { "in progress" => 0, "submitted" => 1 } |
enum status: { "in progress" => 0, "submitted" => 1 } |
||||||
|
validates_with CaseLogValidator |
||||||
end |
end |
||||||
|
Loading…
Reference in new issue