# Q: master/child where children are added with ajax

**URL:** <https://www.ruby-forum.com/t/q-master-child-where-children-are-added-with-ajax/94249>\
**Category:** Rails\
**Created:** [April 26, 2006, 9:32pm UTC](https://www.ruby-forum.com/t/q-master-child-where-children-are-added-with-ajax/94249 "2006-04-26T21:32:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [April 26, 2006, 9:32pm UTC](https://www.ruby-forum.com/t/q-master-child-where-children-are-added-with-ajax/94249/1 "2006-04-26T21:32:43Z")

</div>

Say my user creates an Article and an Article has\_many :links. The edit  
form  
for article contains an “add link” link\_to\_remote that brings up an edit  
line for links for further reading. The problem is that there is that  
the  
Article is not yet saved, so it’s unclear how to accumulate or remove  
these  
items.

I’m sure others have implemented similar things. Hints?

## Thanks

View this message in context:  
[http://www.nabble.com/q%3A-master-child-where-children-are-added-with-ajax-t1513615.html#a4107704](http://www.nabble.com/q%3A-master-child-where-children-are-added-with-ajax-t1513615.html#a4107704)  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [April 26, 2006, 11:28pm UTC](https://www.ruby-forum.com/t/q-master-child-where-children-are-added-with-ajax/94249/2 "2006-04-26T23:28:29Z")

</div>

Steve R. wrote:

> Say my user creates an Article and an Article has\_many :links. The edit  
> form  
> for article contains an “add link” link\_to\_remote that brings up an edit  
> line for links for further reading. The problem is that there is that  
> the  
> Article is not yet saved, so it’s unclear how to accumulate or remove  
> these  
> items.
> 
> I’m sure others have implemented similar things. Hints?
> 
> ## Thanks
> 
> View this message in context:  
> [http://www.nabble.com/q%3A-master-child-where-children-are-added-with-ajax-t1513615.html#a4107704](http://www.nabble.com/q%3A-master-child-where-children-are-added-with-ajax-t1513615.html#a4107704)  
> Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).

Save the parent before using it then you have the ID. If the users  
cancels, destroy it

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [April 26, 2006, 11:46pm UTC](https://www.ruby-forum.com/t/q-master-child-where-children-are-added-with-ajax/94249/3 "2006-04-26T23:46:54Z")

</div>

So you’re advocating:

link\_to\_remote ‘new child’, :url =\> {:action =\> ‘do\_something’}

def do\_something  
save\_master\_record  
fall\_through\_to\_rjs\_add\_child\_records  
end

## BTW: Sorry about the numerous posts of the same question. Nabble hung and I didn’t know whether the post got through. Maybe email _is_ better 🙂

View this message in context:  
[http://www.nabble.com/q%3A-master-child-where-children-are-added-with-ajax-t1513615.html#a4110306](http://www.nabble.com/q%3A-master-child-where-children-are-added-with-ajax-t1513615.html#a4110306)  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).
