title: Saving an array of hashes from jquery in rails
body: <p>I'm a newbie to RoR.  The problem I am trying to solve is how to pass an array of hashes from JQuery to Rails for saving in the database.</p>
  
  <p><strong>Context</strong></p>
  
  <p>In my application, a user is able to drag-and-drop any number of items onto a canvas. This is done using JQuery.</p>
  
  <p>Then the user can save these items, including their X-Y coordinates.</p>
  
  <p>Conceptually I believe that this is saving an array of hashes, where each hash corresponds to an item and consists of an ItemCode, X-coordinate, Y-coordinate.</p>
  
  <p>I am trying to figure out at each step, what method/technique should be used.</p>
  
  <p><strong>Here's what I figured out so far:</strong></p>
  
  <ol>
  <li>? Save an array of objects in JQuery ?</li>
  <li>Serialize this array using jquery.param</li>
  <li>Pass the resulting string as params to Rails using jquery.ajax</li>
  <li>?? Rails controller somehow parses this string and saves it in the database??</li>
  </ol>
  
  <p><strong>Key Questions</strong></p>
  
  <p>A. What format should this serialized string take to be easily parsed by Rails?</p>
  
  <p>I believe Jquery.param will generate something like this (in param form):
  1[item_code]=432&amp;1[x]=250&amp;1[y]=200&amp;2[item_code]=348... I haven't been able to find anything to tell me if Rails can figure out that the first 3 terms describe 1 item, the next 3 describe the next item, etc.</p>
  
  <p>B. What is the Rails way to handle this? In other words, what particular methods should I look at as my tools for putting this params string into the database as a several new entries into the database?</p>
  
  <p>And of course, if there's some completely different way to do this, I'd love to hear it. Thanks.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Just to clarify, the ItemCode is meant to be different from the id of the item entry into the database. ItemCode is used to look up characteristics about the item in other tables.</p>