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

  • SEARCH
  • Home
  • 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 6037459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:04:37+00:00 2026-05-23T06:04:37+00:00

Plugins: Thumbs Up & JQuery 1.5.2 (needed for another old gem) I’m trying to

  • 0

Plugins:
Thumbs Up & JQuery 1.5.2 (needed for another old gem)

I’m trying to render an updated vote count w/o a full HTTP request when a user votes on a post. Currently, it refreshes the page on every vote.

Posts Controller

def vote_up
  post = Post.find(params[:id])
  current_user.vote_exclusively_for(post)
  respond_to do |format|
    format.js
    format.html {rRedirect_to :back}
  end
end

def vote_down
  post = Post.find(params[:id])
  current_user.vote_exclusively_against(post)
  respond_to do |format|
    format.js
    format.html {redirect_to :back}
  end
end

Vote View (each post div has a vote div on the left (digg/reddit style) and content on the right)

 <div class="post">
 <div class="vote">
 <div class="votewrapper">
  <span class="votecount">
  <%= post.votes_for - post.votes_against %>
    </span>
  <div class="votebtn">
   <%= link_to image_tag('vote.png'), vote_up_post_path(post), :method => :post, :format => :js %>
     </div>
   </div>
   </div>
   <div class="postcontent">
   all the post content, timestamp stuff, etc...
   </div>
   </div>

vote_up.erb.js (in the Posts folder).

$(".votecount").html(
"<%= escape_javascript post.votes_for - post.votes_against %>");

I’ve been stuck on this for a while and would very much appreciate any help ya’ll can offer. I’ve seen the Jquery railscast and looked through other Stackoverflow answers, but I’m still quite noobish at Jquery.

  • 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-23T06:04:38+00:00Added an answer on May 23, 2026 at 6:04 am

    It seems like you’ll want to separate out your view code into partials and only refresh one partial when a rating is provided.

    For your controller, instead of:

    respond_to do |format|
        format.js
        format.html {redirect_to :back}
      end
    

    Do something like:

    render :partial => "voutecount"
    

    In your view, move out the votewrapper div into a new file called “_votecount.html.erb” within the same directory, and instead have the render code:

     <%= render :partial => "votecount" %>
    

    If you want to block the rating while it’s refreshing (recommended), then you may want to ajaxify the call and control it more in the js. So, include your javascript within the view:

    <%= javascript_include_tag 'votecount' %>
    

    replace your link_to with good ol’ html to have more info:

    <a href="" class="ratelink" updown="up" theid="123"><img src = "...."></a>
    <a href="" class="ratelink" updown="down" theid="123"><img src = "...."></a>
    

    And create a new votecount.js in your public/javascripts folder with the following content:

      $(function(){
            $(".ratelink").click(function(){
                var val = $(this).attr('updown');
                var theid = $(this).attr('theid');
                $("#votewrapper").block({ //blocks rate-rates while processing
                    message: null,
                    overlayCSS: {
                        backgroundColor: '#FFF',
                        opacity: 0.6,
                        cursor: 'default'
                    },
                });
            if (val == "up") {
            $.ajax({
                    type: 'PUT',
                    url: "/mymodel/voteup?id="+theid,
                    success: function(){
                                $("#votewrapper").unblock();
                                }   
                       });
            } else {
                 $.ajax({
                    type: 'PUT',
                    url: "/mymodel/votedown?id="+theid,
                    success: function(){
                                $("#votewrapper").unblock();
                                }   
                       });
            }
        })
    

    good luck! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

http://plugins.jquery.com/project/conmenu its a plugin for right click menu..... however it has no example usages
I was using jQuery plugins to create a rounded corner for my <li> ,
I'm trying to build an image gallery (or, ideally, find a jquery plugin) that
I am new to Jquery and and trying to build a simple gallery. I
Jquery and other JS frameworks got many lazy image loading plugins, code-blocks. Which basically
There are 62 jQuery Plugins for menus listed on the jQuery website . I
Which rails voting system plugin or gem that has the following features vote up
I have implemented upload feature in ASP.MVC. I am using jQuery.BlockUI and JQuery.Form plugins
jQuery plugins use a pattern like this to hide private functions of a plugin:
jQuery plugins make code much more reusable. I previously made a plugin that would

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.