title: Ajax page.replace_html problems with partials in Rails
body: <p>I am having a problem with a pretty simple AJAX call in rails. I have a blog-style application and each post has a "like" feature. I want to be able to increment the "like" on each post in the index using AJAX onclick. I got it to work; however, the DOM is a bit tricky here, because no matter what partial its looking at, it will only update the TOP partial. so if I click "like" on post #2, it will update and replace the "likes" on post #1 instead.</p>
  
  <p>Code for _post partial:</p>
  
  <pre><code>&lt;some code here...&gt;
  
  &lt;div id="postcontent"&gt;
  Posted &lt;%= post.created_at.strftime("%A, %b %d")%&gt; &lt;br /&gt;
  &lt;/div&gt;
  
  &lt;div id="postlikes"&gt;
  &lt;%= link_to_remote 'Like', :url =&gt; {:controller =&gt; 'posts', :action =&gt; 'like_post', :id =&gt; post.id}%&gt;
  &lt;%= post.like %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>code for _postlikes partial:</p>
  
  <pre><code>&lt;div id="postlikes"&gt;
  &lt;%= link_to_remote 'Like', :url =&gt; {:controller =&gt; 'posts', :action =&gt; 'like_post', :id =&gt; @post.id}%&gt;
  &lt;%= @post.like %&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>like_post.rjs code:</p>
  
  <pre><code>page.replace_html "postlikes", :partial =&gt; "postlikes", :object =&gt; @post
  page.visual_effect :highlight, "postlikes", :duration =&gt; 3
  </code></pre>
  
  <p>So this all works properly for the first "postcontent" div. But this is an index of posts, so if I wanted to updated the second "postcontent" div on the page, it will still replace the html of the first.</p>
  
  <p>I understand the problem, I just don't know how to fix it :)</p>
  
  <p>Thanks in advance!</p>