我有以下型号
A listing has many services
A service has many questions and belongs to listing
A question has many answers
An answer belongs to question and listing
模型设置正确,效果很好。
某些服务有后续问题,例如“你为购买冰淇淋提供糖果折扣吗?”这些问题由管理员输入,这是输入的表格。
= simple_form_for(@listing, :url => service_answer_path, :html => {:class => "form-horizontal" }) do |f|
- @questions.each do |q|
= q.content
= f.fields_for :service_answers do |s|
= s.hidden_field :listing_id, :value => @listing.id
= s.input :content
= f.submit
它在首次提交时效果很好。但是当我尝试编辑时,它为同一个问题提供了多个答案字段。但是,这应该是在循环中运行f.fields_for
。但是,如果我将其移出循环,则问题内容将不会显示在此处显示的每个答案文本字段上。