diff options
author | CassioMarques <cassiommc@gmail.com> | 2009-01-01 16:51:58 -0200 |
---|---|---|
committer | CassioMarques <cassiommc@gmail.com> | 2009-01-01 16:51:58 -0200 |
commit | 34a10b42421cd39520bff067ee9ed5fb83b75b15 (patch) | |
tree | 427a0dfe74081bf9b6b49a248d54e31d7a14d915 /railties/doc/guides/source/activerecord_validations_callbacks.txt | |
parent | d5c72192224048b51097172423ab7357aa1a89e5 (diff) | |
download | rails-34a10b42421cd39520bff067ee9ed5fb83b75b15.tar.gz rails-34a10b42421cd39520bff067ee9ed5fb83b75b15.tar.bz2 rails-34a10b42421cd39520bff067ee9ed5fb83b75b15.zip |
Removed stuff about overriding validate_on_create on the AR Validations and Callbacks Guide, added new section to the Authors page
Diffstat (limited to 'railties/doc/guides/source/activerecord_validations_callbacks.txt')
-rw-r--r-- | railties/doc/guides/source/activerecord_validations_callbacks.txt | 14 |
1 files changed, 1 insertions, 13 deletions
diff --git a/railties/doc/guides/source/activerecord_validations_callbacks.txt b/railties/doc/guides/source/activerecord_validations_callbacks.txt index f57cee3c00..ff2acdf8d5 100644 --- a/railties/doc/guides/source/activerecord_validations_callbacks.txt +++ b/railties/doc/guides/source/activerecord_validations_callbacks.txt @@ -383,19 +383,7 @@ end == Writing your own validation methods -When the built-in validation helpers are not enough for your needs, you can write your own validation methods, by implementing one or more of the +validate+, +validate_on_create+ or +validate_on_update+ methods. As the names of the methods states, the right method to implement depends on when you want the validations to be ran. The meaning of valid is still the same: to make an object invalid you just need to add a message to it's +errors+ collection. - -[source, ruby] ------------------------------------------------------------------- -class Invoice < ActiveRecord::Base - def validate_on_create - errors.add(:expiration_date, "can't be in the past") if - !expiration_date.blank? and expiration_date < Date.today - end -end ------------------------------------------------------------------- - -If your validation rules are too complicated and you want to break them in small methods, you can implement all of them and call one of +validate+, +validate_on_create+ or +validate_on_update+ methods, passing it the symbols for the methods' names. +When the built-in validation helpers are not enough for your needs, you can write your own validation methods. You can do that by implementing methods that verify the state of your models and add messages to their +errors+ collection when they are invalid. You must then register those methods by using one or more of the +validate+, +validate_on_create+ or +validate_on_update+ class methods, passing in the symbols for the validation methods' names. You can pass more than one symbol for each class method and the respective validations will be ran in the same order as they were registered. [source, ruby] ------------------------------------------------------------------ |