That's to be expected with your HTML.

What you currently have will generate HTML that looks like the following if 
you have 3 reviews:

<p id='votes'>1 vote</p>
<p id='votes'>2 votes</p>
<p id='votes'>3 votes</p>

$("#votes").html("3 votes")
$("#votes").html("4 votes")
$("#votes").html("5 votes")

See the problem?

The problem is that each paragraph tag has the same ID. jQuery will only 
update the first one. Each paragraph needs to have a unique ID, then your 
JavaScript to update the paragraph needs to update the specific unique ID.

Including the primary key in the HTML ID is a good solution:

<p id="review_<%= review.id %>">

Then your jQuery can update the specific paragraph that it needs to:

$("#review_<%= review.id %>").html("<%= review.votes_count %>")


-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/8XDnjkoJ3SUJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to