diff --git a/app/models/org_unit.rb b/app/models/org_unit.rb index 9d53961..7454685 100644 --- a/app/models/org_unit.rb +++ b/app/models/org_unit.rb @@ -40,13 +40,8 @@ class OrgUnit < ApplicationRecord absence: { unless: :requires_parent? } validates :resource, - presence: { - if: ->(record) { record.kind&.resource_type }, - message: :required, - }, - absence: { - unless: ->(record) { record.kind&.resource_type }, - } + presence: { if: :requires_resource?, message: :required }, + absence: { unless: :requires_resource? } validate :parent_matches_kind @@ -64,6 +59,10 @@ class OrgUnit < ApplicationRecord kind&.parent_kind end + def requires_resource? + kind&.resource_type + end + private def parent_matches_kind