aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/README
diff options
context:
space:
mode:
authorMikel Lindsaar <raasdnil@gmail.com>2010-01-17 15:17:54 +1100
committerMikel Lindsaar <raasdnil@gmail.com>2010-01-17 15:17:54 +1100
commit4d4bdb0766713d78a2e5126ab4832c45324aa471 (patch)
tree3eaa6b2d2652e6e727e28a9ae84a15efab0f98ae /activemodel/README
parent6f663addaa7ed40f1133687d7a2be0958bf0c059 (diff)
downloadrails-4d4bdb0766713d78a2e5126ab4832c45324aa471.tar.gz
rails-4d4bdb0766713d78a2e5126ab4832c45324aa471.tar.bz2
rails-4d4bdb0766713d78a2e5126ab4832c45324aa471.zip
Added ActiveModel::Errors documentation
Diffstat (limited to 'activemodel/README')
-rw-r--r--activemodel/README32
1 files changed, 32 insertions, 0 deletions
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]