我正在尝试创建一个用茧调用自己的表单,问题 has_many questions,正在生成无限循环:(
模型
class Question < ActiveRecord::Base
has_many :questions,:foreign_key => "parent_id", :dependent =>:destroy
belongs_to :basic_component
attr_accessible :description, :questions_attributes, :questions
end
我的问题_form
<%= semantic_form_for [:admin, @question] do |f| %>
<%= f.inputs do %>
<%= f.input :description %>
<div class="questions">
<%= f.semantic_fields_for :questions do |question| %>
<%= render 'question_fields', :f => question %>
<% end %>
<div class="links">
<%= link_to_add_association("Nova Pergunta", f, :questions, class: 'button') %>
</div>
</div>
<% end %>
<%= f.actions %>
<% end %>
我的_question_fields
<div class="nested-fields">
<%= f.inputs do %>
<%= f.input :description} %>
<div class="questions">
<%= f.semantic_fields_for :questions do |question| %>
<%= render 'question_fields', :f => question %>
<% end %>
<div class="links">
<%= link_to_add_association("Nova Pergunta", f, :questions, class: 'button') %>
</div>
</div>
<% end %>
</div>
无限循环:(,如何解决?
Rendered admin/questions/_question_fields.html.erb (168.4ms)
Rendered admin/questions/_question_fields.html.erb (376.2ms)
Rendered admin/questions/_question_fields.html.erb (586.4ms)
Rendered admin/questions/_question_fields.html.erb (780.2ms)