Files
Klaus/app/models/professor.rb
T
Florian Bogenhard cedeffd2c6 Klaus V2.0
2014-10-13 12:56:00 +02:00

29 lines
645 B
Ruby

class Professor < ActiveRecord::Base
include ToDropdown
has_many :documents
auto_strip_attributes :first_name, squish: true
auto_strip_attributes :first_name, nullify: true
auto_strip_attributes :last_name, squish: true
auto_strip_attributes :last_name, nullify: true
validates :first_name, presence: true
validates :last_name, presence: true
def name_last_first
"#{self.last_name}, #{self.first_name}"
end
def name_first_name
"#{self.first_name} #{self.last_name}"
end
def to_option
[name_last_first, id]
end
def self.to_dropdown
all.order(:last_name, :first_name).map(&:to_option)
end
end