A follow up to this question: what's a RESTful way to save draft posts?
I'm wondering, the submissions that are created always submit to the "create" action in rails. How can I make:
- The first autosave create an entry
- All subsequent autosaves update the saved entry
- The final submission update the same entry
For information, see the related question first. Also, I'm doing this on the Post model, where I added a field "draft" that can be true or false. My jQuery submission is:
$(document).ready(function() {
$('#new_post').append('<div class="temp"> </div>');
setInterval(function() {
{ $('#new_post .temp').html('<input type="hidden" name="post[draft]" id="post_draft" value="true" />');
draft = $('#draft');
}
$('#post_form form[data-remote]').submit();
$('#new_post .temp').html('');
}, 1000*30); // 1000ms * 60s = 1m
});
This file creates a hidden field "draft", submits the form, and then deletes the field.
Also, another file that may be of use is create.js.erb. Once the form is submitted to the controller, this embedded ruby javascript file is called and run. Currently, I make a variable "draft" available to the file such that:
<% if draft %>
#maybe putting code here can change the form to submit to "update" action next time?
<% else %>
# code that executes if it's a final submission, updating tables etc..
<% end %>
Maybe this file is a place to accomplish my task?
If there is more information required, let me know.