2011-12-16 61 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"]} 

,但在我的形式我沒有設置領域'認證者',所以我不明白爲什麼他們有這個屬性。

回答