2011-07-28 76 views
2

我的應用程序有3種型號: 我使用與simple_form寶石嵌套形式顧問,項目與預約Rails的simple_form嵌套形式的聯繫

class Consultant < ActiveRecord::Base 
    has_many :appointments 
end 

class Project < ActiveRecord::Base 
    has_many :appointments, :dependent => :destroy 
    accepts_nested_attributes_for :appointments, :allow_destroy => true 
end 

class Appointment < ActiveRecord::Base 
    belongs_to :consultant 
    belongs_to :project 
end 

我的形式如下:

= simple_nested_form_for(@project) do |f| 

    %div.field 
    = f.input :name, :label => 'Nom du projet' 
    = f.simple_fields_for :appointments do |builder| 
     = render 'appointment_fields', :f => builder 
    = f.link_to_add "ajouter un consultant", :appointments 

    %div 
    %div.actions 
    = f.submit 

與部分:

%p.fields 
    = f.input :consultant_id, :input_html => { :class => 'special' } 
    = f.association :consultant 
    = f.input :nb_days, :input_html => { :class => 'special',:size => 10 } 
    = f.input :rate, :input_html => {:size => 10} 
    = f.link_to_remove "Remove this task" 

是否有可能做一些事情這與simple_form一樣簡單嗎? 答案是肯定的:它很好地工作

+0

什麼是錯誤? – rafaelfranca

+0

錯誤是:/Users/herveleroy/Dropbox/compta/app/views/projects/_appointment_fields.html.haml在哪裏行#4提出: 協會:找不到顧問 – rvopale

+0

協會:顧問找不到 – rvopale

回答

2

錯誤是因爲模型Appointment上沒有關聯調用顧問。改用顧問。