Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7368041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:36:52+00:00 2026-05-29T03:36:52+00:00

I have a table: <table class=articles> <%= render :partial => ‘articles/article’ , :collection =>

  • 0

I have a table:

<table class="articles"> 
      <%= render :partial => 'articles/article' , :collection => @articles  %> 
</table>

and the following partial:

<tr> 
  <td>
    <div id="vote_form"> 
     <% form_tag url_for(article_votes_path(article)), :remote => true  do %> 
      <%= image_submit_tag("vote-arrow-up.png", :alt => "Vote-up", :id => "voteup_button") %>
     <% end %>
    </div>
    <div id="vote_score">
      <% form_tag url_for(article_votes_path(article)), :remote => true  do %>  
         <%= image_submit_tag("vote-arrow-down.png", :alt => "Vote-down", :id => "votedown_button") %> 
      <% end %>
    </div> 
    <div id="vote_score">
    Votes: <%= article.votes.count %>
    </div>
 </td>
</tr>

The Javascript that I am using to update the vote score asynchronously is:

    $("vote_score").update('<%= "Votes: #{@article.votes.count}" %>')

The code works and updates the articles’ corresponding counts correctly but does so only in the first table row. For instance, if I vote on an article in the third row with 5 votes, the score updates asynchronously and 6 is displayed in the first row. And if I vote on an article in the fifth row with 100 votes, the score in the first row will display 101. When the page is reloaded, each article has the correct vote count. How can I modify this javascript to update the count in the vote button’s respective table row?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T03:36:53+00:00Added an answer on May 29, 2026 at 3:36 am

    Element ids are supposed to be unique across the document. That’s why only the first element gets updated.

    You should assign ids that are actually unique. For example, use article id:

        <div id="vote_score_<%= article.id %>">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following relationships setup: class Article < ActiveRecord::Base has_and_belongs_to_many :authors end class
I have a class Articles with a 1:N relation with table Dates. I need
I have this class called Table: class Table { public string Name { get
I have a table called Users ( class User < ActiveRecord::Base ) and a
I am writing a turbogears2 application. I have a table like this: class Order(DeclarativeBase):
If I have a table in MySQL which represents a base class, and I
Let's say I have a table that represents a super class, students . And
I have a simple database table called Entries: class CreateEntries < ActiveRecord::Migration def self.up
I have a declarative table defined like this: class Transaction(Base): __tablename__ = transactions id
Suppose I have an Orders table in my database and a corresponding model class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.