0

我有三个模型(StudentDocumentCV)。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
4

1 回答 1

0

你的答案是:

@cv = @student.documents.build
@cv.type = "CV"

ActiveRecord::Associations::CollectionProxy#build

于 2013-07-15T20:37:13.523 回答