Activerecord 简单的形式,错误与:有多:通过关系?

Activerecord 简单的形式,错误与:有多:通过关系?,activerecord,has-many,simple-form,Activerecord,Has Many,Simple Form,我有3个这样的型号: class CertificatorBtwInstructor < ActiveRecord::Base belongs_to :certificator belongs_to :instructor # other code ... end class Certificator < ActiveRecord::Base has_many :btw_instructors, :class_name => "Certific

我有3个这样的型号:

class CertificatorBtwInstructor < ActiveRecord::Base
    belongs_to :certificator
    belongs_to :instructor
    # other code ...
end

class Certificator < ActiveRecord::Base
    has_many :btw_instructors, :class_name => "CertificatorBtwInstructor"
    has_many :instructors, :through => :btw_instructors
    # other code ...
end

class Instructor < ActiveRecord::Base
    has_many :btw_certificators, :class_name => "CertificatorBtwInstructor"
    has_many :certificators, :through => :btw_certificators
    # other code ...
end
然后,当我提交表单时,没有从“Certificator_id”输入集合中选择任何Certificator,新记录将毫无问题地创建。 但是,当我在“certificator_ID”输入集合中选择任何项目时,会出现一个错误,我使用=f.object.errors将其可视化,错误如下:

{:certificators=>["is not valid"]} 
但是在我的表单中,我没有设置“Certificator”字段,所以我不理解他们为什么会有这个属性。

将其更改为

<%= f.association :certificators, :as => :check_boxes %>
这将在复选框中显示您所有的证书,您应该看看这个 还有这个

<%= f.association :certificators, :as => :check_boxes %>