I am having a problem with a fairly simple AJAX call in rails. I have a blog style app and every post has a “like” function. I want to be able to increment "how" on each column of the index using AJAX onclick. I got him to work; however, the DOM is a bit more complicated here, because no matter what partial image it looks at, it will only update the TOP part. so if I click "like" in post # 2, it will update and replace "like" on post # 1 instead.
Code for _post partial:
<some code here...>
<div id="postcontent">
Posted <%= post.created_at.strftime("%A, %b %d")%> <br />
</div>
<div id="postlikes">
<%= link_to_remote 'Like', :url => {:controller => 'posts', :action => 'like_post', :id => post.id}%>
<%= post.like %>
</div>
code for _postlikes partial:
<div id="postlikes">
<%= link_to_remote 'Like', :url => {:controller => 'posts', :action => 'like_post', :id => @post.id}%>
<%= @post.like %>
</div>
</div>
like_post.rjs code:
page.replace_html "postlikes", :partial => "postlikes", :object => @post
page.visual_effect :highlight, "postlikes", :duration => 3
, div "postcontent". , , "postcontent" div , html .
, , :)
!