Auto saving forms as they type.
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. 👍