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

Can someone help with the following code. Im simply trying to display the total
I am trying to display a simple jtable in frame but It is not
I am trying to display multiple chart's on one screen but i am not
I am trying to display Total Order Amount Per Day in the Present Month.
Am trying to determine whether or not to display an overtime game display flag
I'm trying to display all the users I have not voted on yet! CREATE
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
I am trying to display total of each stock with their description in a
I am trying to display last 3 months of present month (including this total

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.