I have 4 models: Patient
, Admin
, Doctor
, User
. Patient
, Admin
and Doctor
extends User
.
// patient.rb
class Patient < User
end
// doctor.rb
class Doctor < User
end
// admin.rb
class Admin < User
end
However, I cannot get child-class-specific attributes. When I call, for example patient.fathername
, it gives me the error
NoMethodError: undefined method `fathername' for #Patient:0x007fa4c172a188
while I have fathername
column in my Patient
model.
//schema.rb
create_table "patients", force: :cascade do |t|
t.string "fathername"
end
Made some research about the problem, and realized that other people who use STI also encountered with this problem. However, I could not understand any of the solutions and source of the problem. What is wrong with STI and getting attributes?
Aucun commentaire:
Enregistrer un commentaire