I have a recursive relationship between models (Question model appears on multiple levels of the hierarchy): Test --> Questions -------> (has_one) Remediation ------------> (has_many) Remediation_Questions -----------------> (has_one) Question The problem is rails is not building the form correctly (everything works except updating the remediation questions / answers). The only reason i think this might be happening is that the question model is used recursively. ################### Controller: GET /tests/1/edit def edit @test = Test.find(params[:id]) @test.questions.build @test.questions.each do |q| 1.upto(Question::MaxAnswers-q.answers.count) do |qi| q.answers.build end q.build_remediation if q.remediation.nil? 1.upto(Remediation::MaxQuestions-q.remediation.remediation_questions.count) do |rqi| q.remediation.remediation_questions.build end q.remediation.remediation_questions.each do |rq| rq.build_question 1.upto(Question::MaxAnswers-rq.question.answers.count) do |rqis| rq.question.answers.build end end end end #################### View: <% form_for(@test) do |f| %> <%= f.error_messages %> <p> <%= f.label :name %> <%= f.text_field :name %> </p> <div id="questions"> <ol> <% f.fields_for :questions do |q| %> <li> <%= q.label :question, "Question:" %> <%= q.text_field :question %> <ol> <% q.fields_for :answers do |a| %> <li> <%= a.label :answer, "Answer:" %> <%= a.text_field :answer %> <%= a.check_box :correct %> </li> <% end %> </ol> <% q.fields_for :remediation do |r| %> <%= r.label :body, "Remediation:" %><br /> <%= r.text_area :body, :size => "60x4" %> <ol> ********* THIS IS THE PART THAT IS NOT WORKING ******** <% r.fields_for :remediation_questions do |rqs| %> ********* WHEN IT SEES QUESTIONS AGAIN IT BONKS ******* <% rqs.fields_for :questions do |rq| %> <li> <%= rq.label :question, "Remediation Question:" %> <%= rq.text_field :question %> <ol> <% rq.fields_for :answers do |rqa| %> <li> <%= rqa.label :answer, "Answer:" %> <%= rqa.text_field :answer %> <%= rqa.check_box :correct %> </li> <% end %> </ol> <% end %> <% end %> </li> </ol> <% end %> ********* THIS IS THE PART THAT IS NOT WORKING ******* </li> <% end %> </ol> </div> <p> <%= f.submit ''Save'' %> </p> <% end %> ################ MODELS: class Test < ActiveRecord::Base validates_presence_of :name has_many :test_questions has_many :questions, :through => :test_questions accepts_nested_attributes_for :questions, :reject_if => proc { |attrs| attrs[''question''].blank? } end class Question < ActiveRecord::Base MaxAnswers = 4 validates_presence_of :question has_many :test_questions has_many :tests, :through => :test_questions has_many :answers has_one :remediation has_one :remediation_question accepts_nested_attributes_for :answers, :reject_if => proc { |attrs| attrs[''correct''].to_i.zero? && attrs[''answer''].blank? } accepts_nested_attributes_for :remediation, :reject_if => proc { |attrs| attrs[''body''].blank? } end class Remediation < ActiveRecord::Base MaxQuestions = 4 belongs_to :question has_many :remediation_questions accepts_nested_attributes_for :remediation_questions, :reject_if => proc { |attrs| attrs[''question_id''].blank? } end class RemediationQuestion < ActiveRecord::Base belongs_to :remediation belongs_to :question accepts_nested_attributes_for :question, :reject_if => proc { |attrs| attrs[''question''].blank? } end Any idea how to resolve this? Its not displaying the second level questions, nor updating them. However in the show file the models work perfectly. -- Posted via http://www.ruby-forum.com/.