title: Rails / Trix Editor save changes via AJAX to server
body: <p>I am using the very simple to implement <a href="https://github.com/basecamp/trix" rel="nofollow">Trix Editor</a> provided from Basecamp in an "Edit View".</p>
  
  <p>How would one save automatically changes, without having the user to interact through the update button?</p>
  
  <p>I am thinking about something like this:
  <strong>(OLD SCRIPT)</strong></p>
  
  <pre><code>window.setInterval(function() {
      localStorage["editorState"] = JSON.stringify(element.editor)
  }, 5000);
  </code></pre>
  
  <p><strong>What I actually want to do:</strong></p>
  
  <p>post a ajax "post" request to the rails server. something like:</p>
  
  <pre><code>$('trix-editor').on('blur', function() {
  
      var sendname = $('#note_name').val();
      var sendlink = $('#linkinput').val();
      var sendnote = $('input[name="note[note]"]').val();
  
      $.ajax({
          type: "POST",
          url: "/notes",
          data: { note: { name: sendname, link: sendlink, note: sendnote } },
          success: function(data) {
              alert(data.id);
              return false;
          },
              error: function(data) {
              return false;
          }
      });
  </code></pre>
  
  <p>(There is as well the problem with authentification and devise. Only if you are loged in you should be able to send an ajax post request ..??)</p>
  
  <p>Even better would be to save changes only when the user changes some data, and then wait 5s and then push the updated data via json to the server. I have no clue how to do that...</p>
  
  <p>PS: would have loved to tag this question with a "trix-editor" tag, sorry have not enought rep for doing so...</p>