2011-07-28 4 views
2

내 응용 프로그램이 3 개 모델이 있습니다 컨설턴트, 프로젝트와 약속 내가 simple_form 보석과 중첩 된 양식을 사용하고 을레일 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" 

someth 할 수 있습니까? simple_form을 사용하여 간단하게 처리 할 수 ​​있습니까? 대답은 예입니다. 제대로 작동합니다.

+0

무엇이 오류입니까? – rafaelfranca

+0

에로는 다음과 같습니다. /Users/herveleroy/Dropbox/compta/app/views/projects/_appointment_fields.html.haml 여기서 4 번 라인이 발생했습니다 : Association : 컨설턴트를 찾을 수 없음 – rvopale

+0

Association : 컨설턴트를 찾을 수 없습니다. – rvopale

답변

2

모델 약속에 컨설턴트라는 연관이 없기 때문에 오류가 발생했습니다. 컨설턴트를 대신 이용하십시오.