I have a user model that I want to assign to be teacher or student( teacher and student are two separated model ) because if the user signup he would have different registration fields depending on if he is teacher or student. User can be a teacher or student, not both.
I have tried, but don't think that this is the best way to do it. Any help?
class User < AR
has_secure_password
has_one :teacher, class_name: "teacher", foreign_key: "teacher_id", conditions: { role: 'teacher' }
has_one :student, class_name: "student", foreign_key: "student_id", conditions: { role: 'student' }
enum role: [:teacher, :student]
end
class Teacher < AR
belongs_to :user, class_name: "user", foreign_key: "user_id"
end
class Student < AR
belongs_to :user, class_name: "user", foreign_key: "user_id"
end