I had this awesome page. It had several forms on it – all pretty much the same thing – each form was a row of data parsed into form fields from a CSV file. So there were a lot of them (so the user can double check each item before committing the item to the db).
So I was using form_remote_tag to get the job done. Let me say now the tutorials out there are so outdated – they still use
<%=form_remote_tag %>stuff<%=end_form_tag%> which has been deprecated for some time now. I finally figured out that its
<%form_remote_tag %> (sans =) and then just <%end%>.
Great my remote form works.
Now I didn’t want the user to click the submit button twice (didn’t want duplicate objects in the db) so I did this:
<%=submit_tag "add to db", :disable_with=>"adding to db" %>
I didn’t notice that after I added the :disable_with option my ajax request would die, and Rails being nice, sent the request as a regular POST request to the controller – thus the object is created but the page reloads – not fun when you have 80 items to add to the db.
I tore the entire form apart twice and finally today found that the :disable_with option kills the ajax request. I guess I’d have to use button_to with an onclick option that hides the button shows a disabled button and submits the request, but I’ll stick to just having a working ajax form with no fancy disabled buttons.