diff options
author | CassioMarques <cassiommc@gmail.com> | 2008-11-10 20:24:51 -0200 |
---|---|---|
committer | CassioMarques <cassiommc@gmail.com> | 2008-11-10 20:24:51 -0200 |
commit | 0668ab67bf6b32950113995303446840ae57d5d9 (patch) | |
tree | d187c76abc47f08b23f7e793d9940644d16ecbae /railties/doc/guides/source | |
parent | 5affa79f2a5fe73e4bf9ddf1bd2abdfa5667361b (diff) | |
download | rails-0668ab67bf6b32950113995303446840ae57d5d9.tar.gz rails-0668ab67bf6b32950113995303446840ae57d5d9.tar.bz2 rails-0668ab67bf6b32950113995303446840ae57d5d9.zip |
Added documentation for validates_presence_of
Diffstat (limited to 'railties/doc/guides/source')
-rw-r--r-- | railties/doc/guides/source/activerecord_validations_callbacks.txt | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/railties/doc/guides/source/activerecord_validations_callbacks.txt b/railties/doc/guides/source/activerecord_validations_callbacks.txt index b26ebfed41..568ab8bc23 100644 --- a/railties/doc/guides/source/activerecord_validations_callbacks.txt +++ b/railties/doc/guides/source/activerecord_validations_callbacks.txt @@ -237,6 +237,27 @@ The default error message for +validates_numericallity_of+ is "_is not a number_ === The +validates_presence_of+ helper +This helper validates that the attributes are not empty. It uses the +blank?+ method to check if the value is either +nil+ or an empty string (if the string has only spaces, it will still be considered empty). + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_presence_of :name, :login, :email +end +------------------------------------------------------------------ + +NOTE: If you want to be sure that an association is present, you'll need to test if the foreign key used to map the association is present, and not the associated object itself. + +[source, ruby] +------------------------------------------------------------------ +class LineItem < ActiveRecord::Base + belongs_to :order + validates_presence_of :order_id +end +------------------------------------------------------------------ + +The default error message for +validates_presence_of+ is "_can't be empty_". + === The +validates_size_of+ helper === The validates_uniqueness_of+ helper |