# Problem with ajax and nested forms

**URL:** <https://www.ruby-forum.com/t/problem-with-ajax-and-nested-forms/170874>\
**Category:** Rails\
**Created:** [June 23, 2009, 9:50pm UTC](https://www.ruby-forum.com/t/problem-with-ajax-and-nested-forms/170874 "2009-06-23T21:50:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrian\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/cdc98d/32.png) [@Adrian\_D](https://www.ruby-forum.com/u/Adrian_D)\
**Post date:** [June 23, 2009, 9:50pm UTC](https://www.ruby-forum.com/t/problem-with-ajax-and-nested-forms/170874/1 "2009-06-23T21:50:03Z")

</div>

Hi everybody,

I have the following problem:

My model ‘event’ has many ‘eventdates’. I use a nested form to edit  
these events and its eventdates. Everything gets updated using js,  
which works fine.

def update  
@event = Event.find(params[:id])  
respond\_to do |format|  
if @event.update\_attributes(params[:event])  
format.html { redirect\_to(@event) }  
format.js {}  
else  
format.html { render :action =\> “edit” }  
format.js {}  
end  
end  
end

Again, using ajax it is possible to add another eventdate to the  
event.

def add\_eventdate  
@event = Event.find(params[:id])  
@event.eventdates \<\< Eventdate.new

```
render :partial => "tab2", :object => @event

```

end

That works fine, too. But updating the model now is reloading the page  
or actually it is doing redirect\_to(@event). So whenever I have added  
a new child to the event-object it is not updating via ajax anymore it  
seems.

Could you give me a hint what aspect I am missing?

Thanks a lot

---

<div class="post-metadata">

**Author:** ![Adrian\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/cdc98d/32.png) [@Adrian\_D](https://www.ruby-forum.com/u/Adrian_D)\
**Post date:** [June 23, 2009, 10:40pm UTC](https://www.ruby-forum.com/t/problem-with-ajax-and-nested-forms/170874/2 "2009-06-23T22:40:37Z")

</div>

Ok, found the problem. The submit-event wasn’t captured anymore.  
Thanks for reading.
