Q:

Ruby on rails. Ajax, jquery affecting all of same class in partial

I am a complete novice with jquery, but I am trying to add ajax stuff to my rails app. I am rendering a partial, which shows a list of users and a link to rate each user next to them. When I click the link the form successfully renders and submits etc. etc. but the problem I have is that the form renders on every instance of the class.
I have searched and tried using $(this) but that seems to break everything (nothing renders).
Link that is rendered multiple times in the partial:
<td> <%= link_to 'Click here to rate this user', new_user_review_path(:user_id => request.gig.user.id, :gigid => request.gig.id), class: "new-review", remote: true %> </td>

Jquery:
$('.new-review').hide().after('<%= j render("form") %>')

(all instances of .new-review hide and the form gets displayed for every user)
I have tried various things by searching (none of which have worked);
$(this).find('.new-review').hide().after('<%= j render("form") %>')

$(this)('.new-review').hide().after('<%= j render("form") %>')

$(".new-review").click(function(){
    $(this).find('.new-review').hide().after('<%= j render("form") %>');
});

$('.new-review', this).hide().after('<%= j render("form") %>')

Any hints would be appreciated, thanks!

A:

As I understood the problem is that all links have a class '.new-review', so jQuery, instead of using the one you need, uses them all. Somehow you need to sepereate the links. I would suggest chaning a class using this:
#{@user.id}

in your case it would be something like this:
<td> <%= link_to 'Click here to rate this user', new_user_review_path(:user_id => request.gig.user.id, :gigid => request.gig.id), class: "new-review-#{@user.id}", remote: true %> </td>

and for jQuery you would need to change it like this:
$('.new-review-<%= @user.id %>').hide().after('<%= j render("form") %>')

Not sure if I understood the question right but I hope this helps or gives any hints.

