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?
You forgot to tell
validateshow you want to validate:deadline. I think you’re misunderstanding what:ifdoes; the:if => :deadline_in_future?option means:I suspect that you want to validate that the deadline is in the future:
Further details are available in the Active Record Validations and Callbacks Guide.