diff options
author | Mikel Lindsaar <raasdnil@gmail.com> | 2010-01-18 18:29:33 +1100 |
---|---|---|
committer | Mikel Lindsaar <raasdnil@gmail.com> | 2010-01-18 18:29:33 +1100 |
commit | 9aee3659242766896d7d4727a7db425dcb86ded7 (patch) | |
tree | 5499d1de3645454a12924c9d5655daa241f80e98 /activemodel/README | |
parent | 91c38403be88a2a9a3485ddd58237445fa176a77 (diff) | |
download | rails-9aee3659242766896d7d4727a7db425dcb86ded7.tar.gz rails-9aee3659242766896d7d4727a7db425dcb86ded7.tar.bz2 rails-9aee3659242766896d7d4727a7db425dcb86ded7.zip |
Adding ActiveModel::Validations documentation
Diffstat (limited to 'activemodel/README')
-rw-r--r-- | activemodel/README | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/activemodel/README b/activemodel/README index 6673427230..d2b51e2390 100644 --- a/activemodel/README +++ b/activemodel/README @@ -175,4 +175,21 @@ functionality from the following modules: end {Learn more}[link:classes/ActiveModel/Translation.html] -
\ No newline at end of file + +* Providing a full Validation stack for your objects... + + class Person + include ActiveModel::Validations + + attr_accessor :first_name, :last_name + + validates_each :first_name, :last_name do |record, attr, value| + record.errors.add attr, 'starts with z.' if value.to_s[0] == ?z + end + end + + person = Person.new(:first_name => 'zoolander') + person.valid? #=> false + + {Learn more}[link:classes/ActiveModel/Validations.html] + |