# Possible AJAX approach to nested data problem?

**URL:** <https://www.ruby-forum.com/t/possible-ajax-approach-to-nested-data-problem/106462>\
**Category:** Rails\
**Created:** [June 10, 2007, 9:29pm UTC](https://www.ruby-forum.com/t/possible-ajax-approach-to-nested-data-problem/106462 "2007-06-10T21:29:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/76d3ee/32.png) [@DavidB](https://www.ruby-forum.com/u/DavidB)\
**Post date:** [June 10, 2007, 9:29pm UTC](https://www.ruby-forum.com/t/possible-ajax-approach-to-nested-data-problem/106462/1 "2007-06-10T21:29:02Z")

</div>

Greetings,  
I am curious to see if anyone can suggest an efficient approach to a  
problem I am having with nested AJAX forms which I am trying to avoid.

For example, let’s say we have 3 models:

1. Problem (has\_many :questions)
2. Question (belongs\_to :problem, has\_many :answers)
3. Answer (belongs\_to :question)

I have a form that allows a user to document a problem.

Also, the user is able to pose 0…n questions for the documented  
problem and then 0…n possible answers for each question posed.

I was using a form\_remote\_tag to add questions on the problem form  
page by using the form\_remote\_tag to call a method that returns  
another ajax form (form\_remote\_tag) to do add any possible answers to  
the question. I know, I know nested forms-ugh.

The returned answers are showing up in the wrong DOM elements; I’m  
pretty sure I can develop a workaround, but I am getting this feeling  
that I used to when using Java and JSPs and AJAX where code starts  
getting real convoluted. I am sure there are some Rails hackers out  
there that can suggest a cleaner, more Railesque way. Form.serialize  
perhaps?

Thanks-David

The question I have for the community is how you, in general, would  
approach such a problem. Would you use AJAX type forms to keep a user  
on one page or would you split it up.

---

<div class="post-metadata">

**Author:** ![DavidB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/76d3ee/32.png) [@DavidB](https://www.ruby-forum.com/u/DavidB)\
**Post date:** [June 11, 2007, 9:47pm UTC](https://www.ruby-forum.com/t/possible-ajax-approach-to-nested-data-problem/106462/2 "2007-06-11T21:47:30Z")

</div>

> The question I have for the community is how you, in general, would  
> approach such a problem. Would you use AJAX type forms to keep a user  
> on one page or would you split it up.

3 Options

1. Dont use nested forms, because - quite simply - they dont work.  
(easiest)
2. Use link\_to\_remote :with (wont support multipart)
3. Use modal windows ala lightbox. (looks pretty)

---

<div class="post-metadata">

**Author:** ![DavidB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/76d3ee/32.png) [@DavidB](https://www.ruby-forum.com/u/DavidB)\
**Post date:** [June 12, 2007, 1:52am UTC](https://www.ruby-forum.com/t/possible-ajax-approach-to-nested-data-problem/106462/3 "2007-06-12T01:52:04Z")

</div>

Thanks Matt,  
I have kind of reached conclusion 1. I’ll peek at a lightbox approach  
and maybe even an IFRAME. Thanks again-David
