user.rb 549 B

1234567891011121314151617181920
  1. # @author Dumitru Ursu
  2. # A model that represents both the student and the teacher
  3. # A teacher is actually just a course owner
  4. class User < ActiveRecord::Base
  5. # Include default devise modules. Others available are:
  6. # :confirmable, :lockable, :timeoutable and :omniauthable
  7. devise :database_authenticatable, :registerable,
  8. :recoverable, :rememberable, :trackable, :validatable
  9. has_many :courses
  10. def nearest_course
  11. self.courses.order(:starts_at).first
  12. end
  13. def handle
  14. self.name || self.email.split('@').first
  15. end
  16. end