title: Rails how to make sure my AJAX works when using an id that's not yet there
body: <p>I have a <code>current_order</code> that is set up in the application controller like this:</p>
  
  <pre><code>def current_order
    if user_signed_in?
      current_order = Order.where(customer_id: current_user.id, status: :open).first_or_initialize(status: :open)
    else
      current_order = Order.where(customer_id: guest_user.id).first_or_initialize(status: :open)
    end
  end
  </code></pre>
  
  <p>The problem I have is that when adding an <code>order_item</code> to the <code>order</code> for the first time, the order's <code>id</code> is still undefined. </p>
  
  <p>How can I make sure that the AJAX does work when I make my first <code>order_item</code>?</p>