title: Rails 3 each method and Ajax
body: <p>I'm trying to implement some Ajax in my app. A strange behaviour occurs! 
  It's a daycare application. When you show a specific daycare of a specific date you can add some children.
  Originally a list of the children of the database is generated and when you click on one of them the page reload and a new child appears in the attendance list of the daycare. It's working fine, i just wanna add some ajax to be more userfriendly !</p>
  
  <p>When you click on child to add him to the daycare, a daycare_item is created ( join table, an id of the child and the id of the daycare ).</p>
  
  <p>I make the changes to make it ajax ready:</p>
  
  <ul>
  <li>partial for the list</li>
  <li>format.js in the daycare_item controller</li>
  <li>remote true on the link.</li>
  </ul>
  
  <p>It works, no more reload! But the list is updated only when you click a second time on the children list ( the last child added doesn't appears yet ). The js transaction works and if you refresh manually the page, the missing child appears.</p>
  
  <p>I tried few things and here are my results:</p>
  
  <p>In my partial there are </p>
  
  <pre><code>&lt;% @daycare.daycare_items.each do |c| %&gt;
    &lt;li&gt;&lt;%= c.child.firstname &gt;&lt;/li&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>This produce the "lag" effect with one children who is not showing ( until a full refresh )</p>
  
  <p>But if i put a </p>
  
  <pre><code>&lt;%= @daycare.daycare_items.count %&gt;
  </code></pre>
  
  <p>the code is update in time !
  I see nothing strange in the logs. 
  I'm asking why the .each method make a difference?</p>