From 0668ab67bf6b32950113995303446840ae57d5d9 Mon Sep 17 00:00:00 2001 From: CassioMarques Date: Mon, 10 Nov 2008 20:24:51 -0200 Subject: Added documentation for validates_presence_of --- .../source/activerecord_validations_callbacks.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'railties/doc/guides/source') 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 -- cgit v1.2.3