I want to implement AJAX Upvote / Downvote on reviews of product (stackoverflow style).
I have a vote partial generated with each review:
_vote.html.erb
<div id="vote_<%= review.id %>" class="vote">
<%= link_to 'Vote Up', upvote_kata_review_path(@product, @review), :class => "upvote", :method => :post, :remote => true %>
<span><%= review.plusminus %></span> <!--show the current vote-->
<%= link_to 'Vote Down', downvote_kata_review_path(@product, @review), :class => "downvote", :method => :post, :remote => true %>
</div>
and an upvote.js.erb
$(document).ready(function(){
$('#vote_id???').html("<%= escape_javascript render :partial => 'votes/vote' %>");
});
So when user clicks upvote, the partial will be re-rendered to show the new vote count.
The problem is, there are many reviews in a page. After the AJAX call, the JavaScript doesn't know which review's vote partial to re-render. (the $('#vote_id???') part)
Is there any way for Rails to pass the review id to the JavaScript?
Or any other alternative to implement this functionality.
Thanks in advance!
@reviewvariable defined in it, which could be used.