Связь простой_формы Rails с вложенной формой

В моем приложении есть 3 модели: консультант, проект и встреча. Я использую вложенную форму с драгоценным камнем 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 ? Ответ ДА: работает хорошо


person rvopale    schedule 28.07.2011    source источник
comment
ошибка:/Users/herveleroy/Dropbox/compta/app/views/projects/_appointment_fields.html.haml, где поднята строка № 4: Ассоциация: консультант не найден   -  person rvopale    schedule 28.07.2011
comment
Ассоциация :консультант не найден   -  person rvopale    schedule 28.07.2011


Ответы (1)


Ошибки связаны с тем, что в назначении модели нет ассоциации, называемой консультантом. Вместо этого используйте консультантов.

person rafaelfranca    schedule 28.07.2011