Nick Snels
2005-Dec-02 19:35 UTC
undefined local variable or method `errors'' for Listing:Clas
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 -- Posted via http://www.ruby-forum.com/.
Mark Reginald James
2005-Dec-03 13:12 UTC
Re: undefined local variable or method `errors'' for Listing:Clas
Nick Snels wrote:> 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:Classerrors 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.