Ask A Question

Notifications

You’re not receiving notifications from this thread.

Auto saving forms as they type.

Anthony Lee asked in Javascript

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.

Reply

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. 👍

Reply

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

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.