Skip to main content

Auto saving forms as they type.

Javascript • Asked by Anthony Lee

Any good tips on how to auto save the form while user is typing?

For example:
Post is a model. I press create new post to open up a form. While I am typing a post field—it auto saves the post prior to pressing the save button. As user continues to type new things, it continues to save. I have seen some javascript libraries—but was wondering if anyone has implemented this with their rails app.


First thing you'll need is a state column so when you click New, it creates a record in draft state so you can save all the changes to it.

Then I would just add some JS to submit the form via AJAX every once in a while. GMail does it after you stop typing for a few seconds, or you move your cursor out of the text box for example. The exact details on this probably depend a bit upon what your form looks like.

Saving the draft changes is really just submitting a PUT to the update action because the record's in draft state, you can just use the regular update. When you are ready to publish it, you can submit the new state or have a special publish action if you wanted to do more with it.

This would be a great screencast. 👍


Yes Chris, I think this is a common feature now that it will be a great screencast! DO IT.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.