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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:54:04+00:00 2026-05-27T05:54:04+00:00

I have a simple model class Task < ActiveRecord::Base validates :deadline, :if => :deadline_in_future?

  • 0

I have a simple model

class Task < ActiveRecord::Base
  validates :deadline, :if => :deadline_in_future?

  def deadline_in_future?
    Date.today < self.deadline
  end
end

All seems ok, but when I in my rails console

irb(main):001:0> Task.new
ArgumentError: You need to supply at least one validation

Where is the problem?

  • 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-27T05:54:05+00:00Added an answer on May 27, 2026 at 5:54 am

    You forgot to tell validates how you want to validate :deadline. I think you’re misunderstanding what :if does; the :if => :deadline_in_future? option means:

    Validate :deadline only if the deadline_in_future? method returns a true value.

    I suspect that you want to validate that the deadline is in the future:

    validate :deadline_in_future?
    

    Further details are available in the Active Record Validations and Callbacks Guide.

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

Sidebar

Related Questions

Let's say I have a simple model: class Subscription < ActiveRecord::Base attr_accessor :subscribed def
I have a simple model class (Part), which pulls from it's information from a
I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
Assume I have such simple model: class Foo(models.Model): name = models.CharField(max_length=25) b_date = models.DateField()
I have a simple model with news and categories: class Category(models.Model): name = models.CharField()
I have cratet simple Model public class ModelTest { public string MyValue { get;
I have a simple test application: Model: public class Counter { public int Count
I have a similar model Class Student(models.Model): A simple class which holds the basic
I have a simple model: class MediaLink(models.Model): title = models.CharField(max_length=200) subtitle = models.TextField(max_length=2000, unique=False,
Hi Suppose I have a simple model class like this: class TestModel(models.Model): testkey =

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.