title: rails3-jquery-autocomplete reference id with formtastic
body: <p>I just started my Rails app and I have the following problem - I want to use the jQuery UI and autocomplete, and therefore have used the gem rails3-jquery-autocomplete. I also use formtastic for my rails forms. </p>
  
  <p>I have two models:</p>
  
  <p>Customer:</p>
  
  <pre><code>class Customer &lt; ActiveRecord::Base
    has_many :carts
  end
  
  create_table :customer do |t|
    t.column :lastname, :string
    t.column :forename, :string
  end
  </code></pre>
  
  <p>Cart:</p>
  
  <pre><code>class Cart &lt; ActiveRecord::Base
    belongs_to :customer
  end
  
  create_table :cart do |t|
    t.column :costumer_id, :integer
  end
  </code></pre>
  
  <p>As explained in the doc of the gem I made the autocomplete config in my CartController:<code>autocomplete :customer, :lastname, :full =&gt; true</code></p>
  
  <p>In my view with the formtastic code it looks like this:</p>
  
  <pre><code>&lt;%= semantic_form_for @cart do |f| %&gt;
      &lt;%= f.inputs do %&gt;
      &lt;%= f.input :customer,
          :as =&gt; :autocomplete,
          :url =&gt; autocomplete_customer_lastname_carts_path,
          :id_element =&gt; '#cart_customer_id' %&gt;
  </code></pre>
  
  <p>The main question that I have is, how to deal with the id stuff. I mean, I want to store the reference id of the customer in my cart model and not the name itself. I recognized the possibility to take the <code>:id_element</code> option to reference an id input field for storing the id in the form. I figured out, that there seems to be a problem with the formtastic combination, and found a potential <a href="https://github.com/crowdint/rails3-jquery-autocomplete/issues/116#issuecomment-4042298" rel="nofollow">solution</a>.</p>
  
  <p>I could do this, with an <code>&lt;%= f.input :customer_id, :as =&gt; :hidden %&gt;</code>, but I really don't know what to write in the line: <code>&lt;%= f.input :customer, :as =&gt; :autocom...</code>. Is :customer the right solution for this? This approach would give me the following: <code>"cart"=&gt;{"customer"=&gt;"26","customer_id"=&gt;"0"}</code></p>
  
  <p>Does anyone have an idea, possibly I totally misunderstand the whole :id_element thing...</p>