Forum: Ruby on Rails undefined local variable or method `errors' for Listing:Clas

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
91308e9bc88cb069fd1bcf88e910d042?d=identicon&s=25 Nick Snels (nicksnels)
on 2005-12-02 20:35
I have a listing model in which I'm trying to validate a date (2005, 2,
29 - is not a valid date).

  def self.validate_date(year, month, day)
    unless Date::valid_date?(year.to_i, month.to_i, day.to_i)
      errors.add(:start_date, "De startdatum moet geldige datum zijn.")
    end
  end

But everytime I call this code I get:

undefined local variable or method `errors' for Listing:Class

Looking on the internet and in the Rails book errors.add should work and
should raise an error in the view. Anybody any ideas?

Kind regards

Nick
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 mrj (Guest)
on 2005-12-03 14:15
(Received via mailing list)
Nick Snels wrote:
>
> undefined local variable or method `errors' for Listing:Class

errors is an instance method.  Remove the "self." and
call validate_date on the object you are validating.


--
We develop, watch us RoR, in numbers too big to ignore.
This topic is locked and can not be replied to.