validation on the data entered and it reloads the page with an error
displayed, the nested model form is gone because it's not part of the
Is there any way I can change it?
If you need it re-inserted after the page refreshes then you'll have to
re-insert it. This is how HTTP works. There is no state that you don't
provide yourself. HTTP itself is a stateless protocol. Any notion of
state (such as a user session) is all "smoke-and-mirrors" and is why we
need such things as the Rails framework in oder to create that "magic."
In other words, you'll need to store some state information about what
parts need to be added to the rendered template so that you can "replay"
those changes later.
Any request that does not go through XMLHTTPRequest will loose any
information about what was previously rendered. This is why we have a
session store, so that state can be maintained between requests and
"replayed" during response generation. Or, in your case possibly after
1. [client] Send request (attach any cookies that might have been stored
for this domain)
2. [server] Read params from request
3. [server] Restore state (cookies, session data, etc.)
4. [sever] Generate HTML (or other) response
5. [client] Render HTML response in browser, or deal with whatever
6. [server] Forgets about you and anything to do with this request
7. Goto 1
Think of each XMLHTTPRequest as if it were an invisible "window" that
can send requests and get responses in the same manner. From this
of your visible browser window.
This DOM manipulation all happens client-side, which means the server
has no knowledge that this happened. As far as the server is concerned
it generated, and provided to you, what you ask for, so it "forgets"
about you and looks for new requests.