Problem with form update and multiple submit

Here is what I am doing. I do a form_remote_tag in order to update my
data.

I want to be able to prevent the user from going back to the form
with the browser back button, so by having it ajax
after the submit finishes I do a partial render to remove the form
from the page and the browsers cached version of that page no longer
has a form which is what I want.

The problem is that before the ajax call finishes, they could do
multiple hits of the submit button which will send the data to the
browser. I suspect there may be a better way to do this, not sure if
I'd have to write custom javascript however ?

Basically what I do is that I set a session variable
update_in_progress=true, then in the base controller if it's not an
ajax call I set that to false. That seems to work fine as if I am in
my update(), if that is set it means the submit was hit twice and I
just ignore it. The problem is that I still have to handle so sort of
rendering that happens on the unwanted submits.

If I do render :nothing => true, it blows away anything that the
previous render partial had done from
the first submit. So if it had said "record updated successfully" that
then disappears.

If I do

render :update do |page|
# do nothing
end

that seems to put some sort of javascript garbage onto my page, which
I have had problems with that in other places as well.

If I just call exit() to get out of the controller, that causes a
stack dump

Maybe there's an easy answer here, but I don't know what it is as of
yet ...

thanks

If you just want to prevent multiple clicks on submit button or link
then simply add an onclick handler to hide that button or link and
show a progress bar that will prevent your application from receiving
multiple submits.

For example, go to www.sphred.com and click on Sign In or Sign Up link
then try signing in or up. The same is followed here.

The problem is that before the ajax call finishes, they could do
multiple hits of the submit button which will send the data to the
browser. I suspect there may be a better way to do this, not sure if
I'd have to write custom javascript however ?

You can use the :condition and :before options. :conditions allows you to specify a condition, if it evaluates to false, the request is not made. :before specifies some javascript that is run before the request is made. You could check a flag in :condition and set it in :before (and maybe clear it in :complete)

Basically what I do is that I set a session variable
update_in_progress=true, then in the base controller if it's not an
ajax call I set that to false. That seems to work fine as if I am in
my update(), if that is set it means the submit was hit twice and I
just ignore it. The problem is that I still have to handle so sort of
rendering that happens on the unwanted submits.

If I do render :nothing => true, it blows away anything that the
previous render partial had done from
the first submit. So if it had said "record updated successfully" that
then disappears.

If I do

render :update do |page|
# do nothing
end

that seems to put some sort of javascript garbage onto my page, which
I have had problems with that in other places as well.

If I just call exit() to get out of the controller, that causes a
stack dump

I'm guessing you're using :update so that the ajax call updates a certain div. If that's the case then there is no solution. You have to be using not :update in order to have any sort of conditional stuff like this.

You still can't guard against the user having the form visible in 2 separate browser windows and submitting from each one.
fred