* Add custom message for inclusion validation to include the allowed values. * Force user to choose document_type from select lik the one shown at verification form. * Convert stored document_type to a human readable text
21 lines
682 B
Ruby
21 lines
682 B
Ruby
class LocalCensusRecord < ApplicationRecord
|
|
before_validation :sanitize
|
|
|
|
validates :document_number, presence: true
|
|
validates :document_type, presence: true
|
|
validates :document_type, inclusion: { in: ["1", "2", "3"], allow_blank: true }
|
|
validates :date_of_birth, presence: true
|
|
validates :postal_code, presence: true
|
|
validates :document_number, uniqueness: { scope: :document_type }
|
|
|
|
scope :search, ->(terms) { where("document_number ILIKE ?", "%#{terms}%") }
|
|
|
|
private
|
|
|
|
def sanitize
|
|
self.document_type = self.document_type&.strip
|
|
self.document_number = self.document_number&.strip
|
|
self.postal_code = self.postal_code&.strip
|
|
end
|
|
end
|