From 4d4bdb0766713d78a2e5126ab4832c45324aa471 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Sun, 17 Jan 2010 15:17:54 +1100 Subject: Added ActiveModel::Errors documentation --- activemodel/README | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'activemodel/README') diff --git a/activemodel/README b/activemodel/README index c8814a9ea3..9af10d8a38 100644 --- a/activemodel/README +++ b/activemodel/README @@ -78,3 +78,35 @@ functionality from the following modules: {Learn more}[link:classes/ActiveModel/Dirty.html] +* Adding +errors+ support to your object + + Provides the error messages to allow your object to interact with Action Pack + helpers seamlessly... + + class Person + + def initialize + @errors = ActiveModel::Errors.new(self) + end + + attr_accessor :name + attr_reader :errors + + def validate! + errors.add(:name, "can not be nil") if name == nil + end + + def ErrorsPerson.human_attribute_name(attr, options = {}) + "Name" + end + + end + + ... gives you... + + person.errors.full_messages + # => ["Name Can not be nil"] + person.errors.full_messages + # => ["Name Can not be nil"] + + {Learn more}[link:classes/ActiveModel/Errors.html] -- cgit v1.2.3