【发布时间】:2011-07-28 10:33:36
【问题描述】:
我的申请有 3 种模式:顾问、项目和预约 我正在使用带有 simple_form gem 的嵌套表单
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 做这么简单的事情? 答案是肯定的:效果很好
【问题讨论】:
-
错误是:/Users/herveleroy/Dropbox/compta/app/views/projects/_appointment_fields.html.haml 其中第 4 行提出:关联:未找到顾问
-
关联:未找到顾问
标签: ruby-on-rails nested-forms simple-form