Skip to content

Instantly share code, notes, and snippets.

@igmarin

igmarin/doctor.rb

Created Apr 30, 2020
Embed
What would you like to do?
Doctor model, geocoding and validator of documents
class Doctor < ActiveRecord::Base
paginates_per 15
extend FriendlyId
friendly_id :full_name, use: :slugged
belongs_to :city
belongs_to :specialty
has_and_belongs_to_many :subspecialities
validates :document_reference, :city, :name, :address, presence: true
validate :doctor_validation_registration
after_validation :geocode
geocoded_by :full_address
default_scope ->{ order(:last_name)}
def full_address
"#{street}, #{city.name}, #{city.state.name}, US"
end
def doctor_validation_registration
document_reference = DoctorValidation.find_by_registration(self.cedula)
if document_reference.nil?
errors.add(:doctor_validation, "We are sorry but that registration is invalid")
end
end
def full_name
[name, middle_name, last_name].join(' ')
end
mount_uploader :picture, PictureUploader
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.