# Reloading page with errors

**URL:** <https://www.ruby-forum.com/t/reloading-page-with-errors/197139>\
**Category:** Rails\
**Created:** [June 1, 2010, 3:56pm UTC](https://www.ruby-forum.com/t/reloading-page-with-errors/197139 "2010-06-01T15:56:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mlle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mlle](https://www.ruby-forum.com/u/Mlle)\
**Post date:** [June 1, 2010, 3:56pm UTC](https://www.ruby-forum.com/t/reloading-page-with-errors/197139/1 "2010-06-01T15:56:04Z")

</div>

I use javascript to insert a nested model form into a page. If I use  
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  
original template.

Is there any way I can change it?

---

<div class="post-metadata">

**Author:** ![Mlle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mlle](https://www.ruby-forum.com/u/Mlle)\
**Post date:** [June 2, 2010, 9:10pm UTC](https://www.ruby-forum.com/t/reloading-page-with-errors/197139/2 "2010-06-02T21:10:13Z")

</div>

Mlle wrote:

> I use javascript to insert a nested model form into a page. If I use  
> 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  
> original template.
> 
> 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  
response generation.

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  
response contains
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  
invisible window you can use JavaScript to directly manipulate the DOM  
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.
