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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 6 | next ›
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedOct 14, '11 at 12:31a
activeOct 16, '11 at 2:27a
posts6
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Sean Six: 4 posts Tim Shaffer: 2 posts

People

Translate

site design / logo © 2022 Grokbase