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_<%= %>">

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

$("#review_<%= %>").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
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 6 | next ›
Discussion Overview
grouprubyonrails-talk @
postedOct 14, '11 at 12:31a
activeOct 16, '11 at 2:27a

2 users in discussion

Sean Six: 4 posts Tim Shaffer: 2 posts



site design / logo © 2022 Grokbase