Files
grecia/app/models/local_census_record.rb
Senén Rodero Rodríguez a150f2161e Validate inclusion of document type in allowed document types
* 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
2019-11-07 16:26:19 +01:00

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