2012-09-18 132 views
0

我有以下型號
通過嵌套循環領域

 
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在循環中運行。但是,如果我將其移出循環,則問題內容將不會顯示在此處顯示的每個答案文本字段上。 enter image description here
現在我該如何提出這個問題並且回答上面的問題?

回答