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 6658389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:54:31+00:00 2026-05-26T01:54:31+00:00

I am developing a Rails app and need to automatically increment a very simple

  • 0

I am developing a Rails app and need to automatically increment a very simple line bar on a voting list based on a number.

My code – I don’t actually want it to increment on click, but am just providing this as reference:

jQuery:   
$j(".starStats div").click(function() {
 $j(this).parent().animate({
     width: '+=100px'
        }, 500);
            $j(this).prev().html(parseInt($j(this).prev().html()) + 1);
                return false;
});

HTML:

<% (1..5).to_a.reverse.each do |n| %>
<tr class="starStats">
    <td><strong><%= n %> star</strong><span><%= vote.rate_summary ? vote.rate_summary[n].to_i : 0 %></span> <div>&nbsp;</div></td>
<td>(<%= vote.rate_summary ? vote.rate_summary[n].to_i : 0 %>)</td>
</tr>
<% end %>

CSS styling:

.starStats div {  background: #fbbf55; float: right; margin-right: 5px;width: 90px;  }
.starStats span { display: none; } 

enter image description hereExample of Needed Results:


5 star: xxxxxxxxxx (296)
4 star: xxx (28)
3 star: x (15)
2 star: x (16)
1 star: xxxxx (111)


I just need help with the jQuery to implement the correct bar length depending on the voting number.

  • 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-26T01:54:32+00:00Added an answer on May 26, 2026 at 1:54 am

    Would something like this work:

    http://jsfiddle.net/khalifah/HGzqB/

    I took a stab at the ruby code, since I don’t know Ruby.

    JavaScript:

    jQuery:
    $j( ".starStats" ).each(function()
    {
        var totalVotes = parseInt( $j(".total-votes").text() ),
            votes = parseInt( $j(this).find(".votes .number").text() );
        $j( this ).find( ".percent" ).animate({
            width: '+=' + ( votes / totalVotes) * 100
        }, 500);
    });
    

    HTML:

    <% (1..5).to_a.reverse.each do |n| %>
        <tr class="starStats">
            <td><strong><%= n %> star</strong></td>
            <td class="bar"><div class="percent"></div></td>
            <td class="votes">(<span class="number"><%= vote.rate_summary ? vote.rate_summary[n].to_i : 0 %></span>)</td>
        </tr>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an app in Rails 3 and upon signup I need the
I'm developing a Rails 3 app on Ubuntu 10.10 and need to check the
I am developing a rails 2.3.2 app. I need to keep session_id for an
I am developing Rails v2.3 app. and using MySQL v5.1 . I need to
I have a question regarding a simple app I am developing in Rails 3.1,
I've been trying to fix a bug in the Rails app I'm developing, and
I am developing a web app (using rails) that I will be launching within
I'm using the RESTful authentication Rails plugin for an app I'm developing. I'm having
I'm developing a Rails app, and I was just talking with my colleague that
I am developing a rails app and I have 2 different user's role :

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.