Forum: Ruby on Rails undefined local variable or method `errors' for Customer:Cla

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.
54a6fc785e9fcf73ead8e387432b32f5?d=identicon&s=25 Dan Harper (Guest)
on 2006-03-25 03:46
(Received via mailing list)
If I add the following line to my customer model:
errors.add(:shipping_address_postcode, "has invalid format") unless
:shipping_address_postcode =~ /[0-9]*/

I get an error when trying to save a record:

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

I got this example from the Agile book.  Anyone know what I've missed?

Thanks,
Dan
54a6fc785e9fcf73ead8e387432b32f5?d=identicon&s=25 Dan Harper (Guest)
on 2006-03-25 03:55
(Received via mailing list)
Dan Harper wrote:
> If I add the following line to my customer model:
> errors.add(:shipping_address_postcode, "has invalid format") unless
> :shipping_address_postcode =~ /[0-9]*/
>
> I get an error when trying to save a record:
>
> undefined local variable or method `errors' for Customer:Class

It's OK, I figured it out.  I needed to put this line in a "def
validate" section.

Dan
This topic is locked and can not be replied to.