2011-12-16 104 views
0

我有3款这样的:simple_form,错误与:has_many:通过关系?

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 

我的导师新形式我已经设置:

= simple_form_for([:cm, @instructor], :html => { :class => "fAdm" }) do |f| 
    = f.object.errors 
    - others fields ... 
    = f.input :certificator_ids, :required => false, :collection => Certificator.choices_relation_select, :input_html => { :multiple => true, :size => 12 } 
    %div.row.buttons 
     = f.button :submit 

然后,当我提交表单,而不从“certificator_ids”输入集合中选择任何Certificator ,新纪录创建没有问题。 但是,当我选择在“certificator_ids”输入收集任何项目,一个错误出现(我用= f.object.errors进行可视化),错误是这样的:

{:certificators=>["is not valid"]} 

,但在我的形式我没有设置领域'认证者',所以我不明白为什么他们有这个属性。

回答