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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:24:49+00:00 2026-05-28T01:24:49+00:00

I am trying to display total votes cast on a post with thumbs_up gem

  • 0

I am trying to display total votes cast on a post with thumbs_up gem but it does not seem to work.

Here is my code

    def vote_up
    begin
      post = Post.find(params[:id])
      current_user.vote_for(post)
      redirect_to :back
      flash[:sucess] = "You have voted successfully"
      @votes_total = post.votes_for
    rescue ActiveRecord::RecordInvalid
        redirect_to :back
        flash[:error] = "You have already voted for this one"
    end

  end

In the view :-

<%="Total votes = #{@votes_total}"%>

I get the flash message “You have voted successfully” but my votes count are not getting displayed.

This is what I have in my log files :-

[1m[36m (0.3ms)[0m [1mSELECT COUNT(*) FROM “votes” WHERE
“votes”.”voteable_id” = 12 AND “votes”.”voteable_type” = ‘Post’ AND
“votes”.”vote” = ‘t'[0m 0

— Update —

Update my post controller with this code :-

def vote_up
    begin
      post = Post.find(params[:id])
      current_user.vote_for(post)
      @votes_total = post.votes_for
      render :template => "home/index"
      flash[:sucess] = "You have voted successfully"

    rescue ActiveRecord::RecordInvalid
        redirect_to :back
        flash[:error] = "You have already voted for this one"
    end

  end

Help please.

  • 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-28T01:24:50+00:00Added an answer on May 28, 2026 at 1:24 am

    It does not display because you are redirecting. When redirecting you are basically doing a new request and the instance variables of the former request won’t be available anymore. Flash does work, because it uses the session. Solution: either set @votes_total in the action you are redirecting to or use render instead of redirect_to.

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

Sidebar

Related Questions

I am trying to display the total amount that each user would get in
I am trying to display Total Order Amount Per Day in the Present Month.
I'm trying to display all the users I have not voted on yet! CREATE
I am trying to display a sub-total of the database value bound to each
I'm trying to display the number of total number of sales for the currently
I'm a total noob and I'm trying to display a little submarine I built
im trying to display data on the footer in jqgrid, but it only displays
I have been trying to figure out a way to make this work, but
I'm trying to display a row, 'Total', that will do a sum of the
Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s

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.