title: Communicating with database from javascript file in Rails app
body: <p>Disclaimer: I'm a rails newbie, so I apologize if I'm going at this problem entirely wrong. I'm using jQuery UI's draggable functionality, and after a user drags an element, I need to add a new entry into a database. My javascript looks like this:</p>
  
  <pre><code>$(function() {
      $( ".staged" ).draggable({ appendTo: 'body',
          containment: 'window',
          scroll: false,
          helper: 'clone',
          stop: function(e,ui) {
              // around here, I'd like to create a new entry in the database called "placed_images"
              var url = this.getAttribute("src");
              x = ui.offset.left;
              y = ui.offset.top;
              var div = document.createElement("div");
              div.className += "placed";
              div.innerHTML = '&lt;img src="'+url+'" class="placed" style="top:'+y+'px;left:'+x+'px;"&gt;'
              document.getElementById('page').appendChild(div);
              $(function() {
                  $( ".placed" ).draggable();
              });
          }
      });
  });
  </code></pre>
  
  <p>The above code is in the pages.js file in the javascript folder of my app. I know how to make a new entry in a database by using a form action that sends params to the "create" function in a controller. The code should have the same effect as:</p>
  
  <pre><code>form_for(:placed_image, :url =&gt; {:action =&gt; 'create'}) do |f| ...
  </code></pre>
  
  <p>Except without a form and it should happen asynchronously, without a page reload. Like I said, this might be a boneheaded way of going about this, I'm not sure. But if you know of a library, gem, or tutorial that might help me out, that'd be greaaaat.</p>