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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:43:16+00:00 2026-05-13T12:43:16+00:00

I have a model Vote , and I’m using an after_validation callback. class Vote

  • 0

I have a model Vote, and I’m using an after_validation callback.

class Vote < ActiveRecord::Base

  after_validation :destroy_reciprocal_votes

  belongs_to :voteable, :polymorphic => true
  belongs_to :voter, :polymorphic => true

  private

  def destroy_reciprocal_votes
    votes = Vote.delete_all(:vote => false, :voteable_type => "Recipe", :voteable_id => self.voteable_id, :voter_type => "User", :voter_id => self.voter_id)
  end
end

You can see that in my method destroy_reciprocal_votes, I called self.voteable_id and self.voter_id, why does this return nil? and how should I retrieve my id’s here?

When I do it in console it works fine:

>> voteable_id = "3"
>> voter_id = "162"
>> Vote.delete_all(:vote => false, :voteable_type => "Recipe", :voteable_id => voteable_id, :voter_type => "User", :voter_id => voter_id)
  • 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-13T12:43:16+00:00Added an answer on May 13, 2026 at 12:43 pm

    You don’t have to refer to id as long as you specify an association. Try this:

    Vote.delete_all(:vote => false, :voteable_type => "Recipe", :voteable_id => voteable, :voter_type => "User", :voter_id => voter)
    

    Update

    Changed to :voteable_id => voteable.

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

Sidebar

Related Questions

#Vote Model belongs_to :voteable, :polymorphic => true belongs_to :voter, :polymorphic => true #votes table
I have some model objects I'm using in my Java client application. Later these
I have a model, Thing, that has a has_many with ThingPhoto, using Paperclip to
Let's say I have a model like this class Foo(db.Model): id = db.StringProperty() bar
I have a model called Vote that gets changed very frequently (people voting on
I have a model called Post, with a column called vote, and it has
I'm using a Vote model which can be generically linked to several different models
I have a model being populated by my data layer and then I have
I have a model Question with a field called userid , before one ask
I have a model Foo which have a ForeignKey to the User model. Later,

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.