Targeting row when responding with js rails

Posted by berto77 on Stack Overflow See other posts from Stack Overflow or by berto77
Published on 2012-07-06T03:13:27Z Indexed on 2012/07/06 3:15 UTC
Read the original article Hit count: 130

Filed under:

I have an application where a user can vote on reviews. They can vote up or down. Now when there's a listing of reviews, I have a problem targeting the review the user voted on.

I'm using a respon_to block in my rails controller and responding with js. So for instance, I have a vote_up method, and a vote_up.js.erb template. in that template, I have the following:

var id = $('article.comment').attr('id').split('_')[1];
alert("id: " + id);
$('.votecomment_' + id).find('.score').html("<%= @review2.vote_total %>");

I'm just alerting the id. The problem is that the id always returns the value of the first review found on the page. How can I pass the context aka this, to javascript, so I can figure out which review to target?

© Stack Overflow or respective owner

Related posts about ruby-on-rails-3