Files
grecia/app/models/local_census_record.rb
Javi Martín 2b4b2f3442 Use aria-label in admin table actions
This way screen reader users will know which record they're going to
access when focusing on a link to a certain action. Otherwise they'd
hear something like "Edit, link", and they wouldn't know which record
they'll end up editing if they follow the link.
2021-09-20 20:27:37 +02:00

25 lines
782 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}%") }
def title
"#{ApplicationController.helpers.humanize_document_type(document_type)} #{document_number}"
end
private
def sanitize
self.document_type = document_type&.strip
self.document_number = document_number&.strip
self.postal_code = postal_code&.strip
end
end