我有三个模型(Student
、Document
和CV
)。Document
具有单表继承。我的问题是如何创建简历@student
?我试过@student.documents.new(type: CV)
了,但这给了我:
错误
NoMethodError: undefined method `safe_constantize' for #<Class:0x007fd1819adad0>
我知道我可以做到CV.new(owner: @student)
,但这感觉不那么优雅。
楷模
class Student < ActiveRecord::Base
has_many :documents,
as: :owner
end
class Document < ActiveRecord::Base
has_many :documents,
as: :owner
end
class CV < Document
end