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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:19:20+00:00 2026-06-09T13:19:20+00:00

I am implementing an up-voting system on an app I am building very similar

  • 0

I am implementing an up-voting system on an app I am building very similar to the one here on stackoverflow. When a user clicks upvote or downvote, an ajax request is sent to one of my controllers which them updates a couple of tables. Once that is done, I use the respond_to to routes to a js.erb file that executes jquery to update the user display. However, the jquery is not being executed. When I lick upvote/downvote, the controller code executes properly (I can see it in the rails console), but the user display is not updated. Upon refresh the user display is updated, however, not asynchronously. I know the jquery is not being executed b/c in the fire bug console I can see my jquery code – it just is not being applied. Here is my upvote controller code:

def upvote
        @post = Post.find(params[:id])

        @user_vote = current_user.votes.where(post_id: @post.id).first
        if @user_vote.blank?
            Vote.create(user_id: current_user.id, post_id: @post.id, vote: 1)
            @post.upvotes += 1
        elsif @user_vote.vote.to_i == 0
            @user_vote.vote = 1
            @post.upvotes += 1
        elsif @user_vote.vote.to_i == 1
            return redirect_to :back, :alert => 'You have already upvoted the post'
        elsif @user_vote.vote.to_i == 2
            @user_vote.vote = 1
            @post.downvotes -= 1
            @post.upvotes += 1
        end

        respond_to do |format|
            if @post.save and @user_vote.save
                format.js { }
            else 
                format.html { redirect_to :back, :alert => 'There was an error in upvoting the post' }
            end
        end

    end 

This is my upvote.js.erb file:

$('#post-action-<%= @post.id %>').html("upvote");
// this normally renders a partial (below), but I am rendering "upvote" until I can fix this
// escape_javascript(<%= render :partial => 'post_voting', :locals => { post: @post, user_vote: @user_vote } %>) 

Here is my html:

         <div class="post_actions" id='post-action-<%= "#{post.id}" %>' >

            <%= render :partial => 'post_voting', :locals => { post: post, user_vote: current_user.votes.where( post_id: post.id ).first } %>

        </div>

Here is my firebug console output: https://i.stack.imgur.com/ntXeM.png

EDIT

I noticed I am getting an error in on my server:

Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2012-08-09 06:33:42 -0700
Served asset /bootstrap.js - 304 Not Modified (0ms)
  • 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-06-09T13:19:21+00:00Added an answer on June 9, 2026 at 1:19 pm

    After messing around with the jquery, I noticed some things. Firstly, I needed to minify my code (taking out all comments and unused spaces). I took this:

    $('#post-action-<%= @post.id %>').html("upvote");
    // this normally renders a partial (below), but I am rendering "upvote" until I can fix this
    // escape_javascript(<%= render :partial => 'post_voting', :locals => { post: @post, user_vote: @user_vote } %>) 
    

    and changed it to this:

    $('#post-action-<%= @post.id %>').html("upvote");
    

    The code was then working and the user display was updating to show “upvote.” Perfect. So then I replaced the above code with this:

    $('#post-action-<%= "#{@post.id}" %>').html("<%= escape_javascript(render :partial => 'post_voting', :locals => { :post => @post, :user_vote => @user_vote }) %>");
    

    and KAPOW! It works. So happy to have solved this! MINIFY YOUR JQUERY PEOPLE!

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

Sidebar

Related Questions

I'm implementing a voting system like the one used by stackoverflow. It's working with
Implementing Ajax requests in my rails 3 app has been one of the most
We are implementing a voting-system inside an facebook app. The users are able to
I'm implementing a voting system like Stackoverflow's. How can I implement this so it
im currently implementing a security module in a voting system and i was wondering
I'm implementing a small voting system on my website. I came up with three
I'm looking at implementing a live voting system on my website . The website
I'm implementing a voting system for a relatively large website and I'm wondering where
Implementing an app where the user can log in I have the following situation:
When implementing a hash table using a good hash function (one where the probability

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.