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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:18:35+00:00 2026-05-13T13:18:35+00:00

Oddly enough, my model passes validation just fine, and acts as expected, however I

  • 0

Oddly enough, my model passes validation just fine, and acts as expected, however I still have the error rendered to the view.

# Controller
def up
  @vote = Vote.create :vote => true, :voter => current_user, :voteable => Recipe.find(params[:id])
  respond_to do |format|
    format.js { render :json => {:model => 'vote', :success => @vote.valid?, :errors => @vote.errors }}
  end
  @vote.errors.clear # <= doesn't seem to help
end

The model I wrote has a custom validation:

class Vote < ActiveRecord::Base

  # ... associations etc.

  validate :voter_voting_too_frequently?

  private

  def voter_voting_too_frequently?
    last_vote_cast_by_voter = Vote.find_last_by_voter_id self.voter
    unless last_vote_cast_by_voter.nil? || last_vote_cast_by_voter.created_at < 5.seconds.ago
      errors.add_to_base("You can only vote every 5 seconds.")
    end
  end
end

And lastly, the response that is rendered to the view: (returned as js no doubt, but would be the same if it were in a <div>)

{"errors":[["base","You can only vote every 5 seconds."]],"model":"vote","success":false}

And even though it was successful, this is continuously returned.

Ideas on how to debug this?

  • 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-13T13:18:35+00:00Added an answer on May 13, 2026 at 1:18 pm

    It doesn’t look like it is passing the validation since the success status is false.

    If you take a look at you custom validation it seems that the “unless” keyword has caused some confusion.

    Try:

    if !last_vote_cast_by_voter.nil? && last_vote_cast_by_voter.created_at < 5.seconds.ago
      errors.add_to_base ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Oddly enough, googling this error doesn't produce any results. Is there any quick fix
Oddly enough, most of this works as it has been written, however I'm not
I have a thinking-sphinx app and oddly enough the files in /db/sphinx/development/ have not
I have a mod_rails server where disk space, oddly enough, is at a premium.
You can set the Vim color scheme by issuing :colorscheme SCHEME_NAME but, oddly enough,
I have an oddly difficult task to perform. I thought it would be easy,
I sometimes get a null pointer exception with my code. Oddly enough, this does
I found many things about converting Groovy to JSON, but oddly enough, not the
$test = 'love'; $eff = end(explode('ov',$test)); I can't figure it out; oddly enough, this
Oddly enough, I can't find any info on this topic: user profile pictures. 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.