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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:20:14+00:00 2026-05-24T11:20:14+00:00

I’m currently using the thumbs_up gem to allow my users to vote on posts

  • 0

I’m currently using the thumbs_up gem to allow my users to vote on posts and am having an issue with the vote_exclusively_for/against methods. Here is the gem’s github link: https://github.com/brady8/thumbs_up. The gem works fine with the vote_up and vote_down methods, but when I change it to vote_exclusively_for (which is supposed to replace a previous down vote w/ an up vote), I get the following error in my development log:

 ActiveRecord::RecordInvalid (Validation failed: Voteable has already been taken):
 app/controllers/posts_controller.rb:97:in `vote_up'

It appears that a method inside the gem is not clearing out the previous vote before initiating the new vote. Here is my code in the posts_controller:

  def vote_up
    @user = current_user
    @post = Post.find(params[:id])
    @user.vote_exclusively_for(@post)
    redirect_to (..)
 end

Here is the code from the gem:

  def vote_exclusively_for(voteable)
    self.vote(voteable, { :direction => :up, :exclusive => true })
   end

 def vote(voteable, options = {})
    raise ArgumentError, "you must specify :up or :down in order to vote" unless options[:direction] && [:up, :down].include?(options[:direction].to_sym)
    if options[:exclusive]
     self.clear_votes(voteable)
    end
    direction = (options[:direction].to_sym == :up)
    Vote.create!(:vote => direction, :voteable => voteable, :voter => self)
  end

 def clear_votes(voteable)
    Vote.where(
      :voter_id => self.id,
      :voter_type => self.class.name,
      :voteable_id => voteable.id,
      :voteable_type => voteable.class.name
    ).map(&:destroy)
  end

I’m not sure why the clear_votes method isn’t deleting the previous vote. Any help would be greatly appreciated.

  • 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-24T11:20:14+00:00Added an answer on May 24, 2026 at 11:20 am

    Try running this in the console and see if it works or not:

    user = ... # fetch the right user
    post = ... # fetch the right post
    
    Vote.where(
      :voter_id => user.id,
      :voter_type => User,
      :voteable_id => post.id,
      :voteable_type => Post
    ).map(&:destroy)
    

    You can also temporarily edit clear_votes and do some logging there to make sure that the self.class.name and voteable.class.name are referring to the right classes. Also log the where method call with a count before the map to the destroy command to ensure that it’s not returning an empty array.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.